Cascading Style Sheets ( CSS ) is a style sheet language used for specifying the presentation and styling of a document written in a markup language such as HTML or XML (including XML dialects such as SVG , MathML or XHTML ). CSS is a cornerstone technology of the World Wide Web , alongside HTML and JavaScript .
35-411: CSS is designed to enable the separation of content and presentation , including layout , colors , and fonts . This separation can improve content accessibility , since the content can be written without concern for its presentation; provide more flexibility and control in the specification of presentation characteristics; enable multiple web pages to share formatting by specifying the relevant CSS in
70-407: A declaration block . In CSS, selectors declare which part of the markup a style applies to by matching tags and attributes in the markup itself. Selectors may apply to the following: Classes and IDs are case-sensitive, start with letters, and can include alphanumeric characters, hyphens, and underscores. A class may apply to any number of instances of any element. An ID may only be applied to
105-459: A metre , centi being the SI prefix for a factor of 1 / 100 . Equivalently, there are 100 centimetres in 1 metre. The centimetre was the base unit of length in the now deprecated centimetre–gram–second (CGS) system of units. Though for many physical quantities, SI prefixes for factors of 10 —like milli- and kilo- —are often preferred by technicians, the centimetre remains
140-422: A pseudo-element makes a selection that may consist of partial elements, such as :: first-line or :: first-letter . Note the distinction between the double-colon notation used for pseudo-elements and the single-colon notation used for pseudo-classes. Multiple simple selectors may be joined using combinators to specify elements by location, element type, id, class, or any combination thereof. The order of
175-445: A 0 to 255 scale (e.g. rgb ( 255 , 0 , 0 ) ), RGBA values that specify both color and alpha transparency (e.g. rgba ( 255 , 0 , 0 , 0 . 8 ) ), or HSL or HSLA values (e.g. hsl ( 0 100 % 50 %) , hsl ( 0 100 % 50 % / 0 . 8 ) ). Non-zero numeric values representing linear measures must include a length unit, which is either an alphabetic code or abbreviation, as in 200px or 50vw ; or
210-420: A balance between design intent and user accessibility. Multiple style sheets can be imported. Different styles can be applied depending on the output device being used; for example, the screen version can be quite different from the printed version, so authors can tailor the presentation appropriately for each medium. The style sheet with the highest priority controls the content display. Declarations not set in
245-423: A design without compromising the overall layout. Specificity refers to the relative weights of various rules. It determines which styles apply to an element when more than one rule could apply. Based on the specification, a simple selector (e.g. H1) has a specificity of 1, class selectors have a specificity of 1,0, and ID selectors have a specificity of 1,0,0. Because the specificity values do not carry over as in
280-542: A free CSS validation service for CSS documents. In addition to HTML, other markup languages support the use of CSS including XHTML , plain XML , SVG , and XUL . CSS is also used in the GTK widget toolkit . CSS has a simple syntax and uses a number of English keywords to specify the names of various style properties. A style sheet consists of a list of rules . Each rule or rule-set consists of one or more selectors , and
315-414: A heading element defined with red text would be written as: Using CSS, the same element can be coded using style properties instead of HTML presentational attributes: The advantages of this may not be immediately clear but the power of CSS becomes more apparent when the style properties are placed in an internal style element or, even better, an external CSS file. For example, suppose the document contains
350-408: A percentage sign, as in 80% . Some units – cm ( centimetre ); in ( inch ); mm ( millimetre ); pc ( pica ); and pt ( point ) – are absolute , which means that the rendered dimension does not depend upon the structure of the page; others – em ( em ); ex ( ex ) and px ( pixel ) – are relative , which means that factors such as the font size of a parent element can affect
385-536: A separate .css file, which reduces complexity and repetition in the structural content; and enable the .css file to be cached to improve the page load speed between the pages that share the file and its formatting. Separation of formatting and content also makes it feasible to present the same markup page in different styles for different rendering methods, such as on-screen, in print, by voice (via speech-based browser or screen reader ), and on Braille-based tactile devices. CSS also has rules for alternate formatting if
SECTION 10
#1732765155278420-561: A single element. Pseudo-classes are used in CSS selectors to permit formatting based on information that is not contained in the document tree. One example of a widely used pseudo-class is : hover , which identifies content only when the user "points to" the visible element, usually by holding the mouse cursor over it. It is appended to a selector as in a : hover or # elementid : hover . A pseudo-class classifies document elements, such as : link or : visited , whereas
455-619: A site or even across sites, promoting consistency and efficiency. For example, headings ( h1 elements), sub-headings ( h2 ), sub-sub-headings ( h3 ), etc., are defined structurally using HTML. In print and on the screen, choice of font , size , color and emphasis for these elements is presentational . Before CSS, document authors who wanted to assign such typographic characteristics to, say, all h2 headings had to repeat HTML presentational markup for each occurrence of that heading type. This made documents more complex, larger, and more error-prone and difficult to maintain. CSS allows
490-443: A style sheet, allowing for shorter CSS. Inheritance in CSS is not the same as inheritance in class-based programming languages , where it is possible to define class B as "like class A, but with modifications". With CSS, it is possible to style an element with "class A, but with modifications". However, it is not possible to define a CSS class B like that, which could then be used to style multiple elements without having to repeat
525-431: A summary of selector syntax indicating usage and the version of CSS that introduced it. A declaration block consists of a pair of braces ( {} ) enclosing a semicolon-separated list of declarations . Each declaration itself consists of a property , a colon ( : ), and a value . Optional white-space may be around the declaration block, declarations, colons, and semi-colons for readability. Properties are specified in
560-403: Is ignored. This code snippet: is functionally equivalent to this one: Separation of content and presentation Separation of content and presentation (or separation of content and style ) is the separation of concerns design principle as applied to the authoring and presentation of content. Under this principle, visual and design aspects (presentation and style) are separated from
595-447: Is not a rigid guideline, but serves more as best practice for keeping appearance and structure separate. In many cases, the design and development aspects of a project are performed by different people, so keeping both aspects separated ensures both initial production accountability and later maintenance simplification, as in the don't repeat yourself (DRY) principle. LaTeX is a document markup language that focuses primarily on
630-422: The CSS portion of a HTML document, where the formatting, document specifications and other visual attributes are specified. Under this methodology, academic writings and publications can be structured, styled and typeset with minimal effort by its creators. In fact, it also prevents the end-users — who are usually not trained as designers themselves — from alternating between tweaking the formatting and working on
665-530: The CSS standard. Each property has a set of possible values. Some properties can affect any type of element, and others apply only to particular groups of elements. Values may be keywords, such as "center" or "inherit", or numerical values, such as 200px (200 pixels), 50vw (50 percent of the viewport width) or 80% (80 percent of the parent element's width). Color values can be specified with keywords (e.g. " red "), hexadecimal values (e.g. # FF0000 , also abbreviated as # F00 ), RGB values on
700-478: The HTML. CSS lets authors move much of that information to another file, the style sheet, resulting in considerably simpler HTML. And additionally, as more and more devices are able to access responsive web pages, different screen sizes and layouts begin to appear. Customizing a website for each device size is costly and increasingly difficult. The modular nature of CSS means that styles can be reused in different parts of
735-460: The content and structure of a document. When a document is prepared using the LaTeX system, the source code of the document can be divided into two parts: the document body and the preamble (and the style sheets). The document body can be likened to the body of a HTML document, where one specifies the content and the structure of the document, whereas the preamble (and the style sheets) can be likened to
SECTION 20
#1732765155278770-547: The content is accessed on a mobile device . The name cascading comes from the specified priority scheme to determine which declaration applies if more than one declaration of a property match a particular element. This cascading priority scheme is predictable. The CSS specifications are maintained by the World Wide Web Consortium (W3C). Internet media type ( MIME type ) text/css is registered for use with CSS by RFC 2318 (March 1998). The W3C operates
805-487: The core material and structure (content) of a document. A typical analogy used to explain this principle is the distinction between the human skeleton (as the structural component) and human flesh (as the visual component) which makes up the body's appearance. Common applications of this principle are seen in Web design ( HTML vs. CSS ) and document typesetting ( Lambert's document body vs. its preamble). This principle
840-427: The decimal system, commas are used to separate the "digits" (a CSS rule having 11 elements and 11 classes would have a specificity of 11,11, not 121). Thus the selectors of the following rule result in the indicated specificity: Consider this HTML fragment: In the above example, the declaration in the style attribute overrides the one in the <style> element because it has a higher specificity, and thus,
875-627: The designers, or may remove all added styles, and view the site using the browser's default styling, or may override just the red italic heading style without altering other attributes. Browser extensions like Stylish and Stylus have been created to facilitate the management of such user style sheets. In the case of large projects, cascading can be used to determine which style has a higher priority when developers do integrate third-party styles that have conflicting priorities, and to further resolve those conflicts. Additionally, cascading can help create themed designs, which help designers fine-tune aspects of
910-508: The document itself. Similar to the case with HTML and CSS, the separation between content and style also allows a document to be quickly reformatted for different purposes, or a style to be re-purposed across multiple documents as well. Centimetre A centimetre or centimeter ( US/Philippine spelling ), with SI symbol cm , is a unit of length in the International System of Units (SI) equal to one hundredth of
945-407: The highest priority source are passed on to a source of lower priority, such as the user agent style. The process is called cascading . One of the goals of CSS is to allow users greater control over presentation . Someone who finds red italic headings difficult to read may apply a different style sheet. Depending on the browser and the website, a user may choose from various style sheets provided by
980-429: The modifications. Given the following style sheet: Suppose there is a p element with an emphasizing element ( <em> ) inside: If no color is assigned to the em element, the emphasized word "illustrate" inherits the color of the parent element, p. The style sheet p has the color pink, hence, the em element is likewise pink: This is to illustrate inheritance The whitespace between properties and selectors
1015-1095: The paragraph appears green: To demonstrate specificity Inheritance is a key feature in CSS; it relies on the ancestor-descendant relationship to operate. Inheritance is the mechanism by which properties are applied not only to a specified element but also to its descendants. Inheritance relies on the document tree, which is the hierarchy of XHTML elements in a page based on nesting. Descendant elements may inherit CSS property values from any ancestor element enclosing them. In general, descendant elements inherit text-related properties, but their box-related properties are not inherited. Properties that can be inherited are color, font, letter spacing, line-height, list-style, text-align, text-indent, text-transform, visibility, white-space, and word-spacing. Properties that cannot be inherited are background, border, display, float and clear, height, and width, margin, min- and max-height and -width, outline, overflow, padding, position, text-decoration, vertical-align, and z-index. Inheritance can be used to avoid declaring certain properties over and over again in
1050-540: The rendered measurement. These eight units were a feature of CSS 1 and retained in all subsequent revisions. The proposed CSS Values and Units Module Level 3 will, if adopted as a W3C Recommendation, provide seven further length units: ch ; Q ; rem ; vh ; vmax ; vmin ; and vw . Before CSS, nearly all presentational attributes of HTML documents were contained within the HTML markup. All font colors, background styles, element alignments, borders, and sizes had to be explicitly described, often repeatedly, within
1085-463: The selectors is important. For example, div . myClass { color : red ;} applies to all elements of class myClass that are inside div elements, whereas . myClass div { color : red ;} applies to all div elements that are inside elements of class myClass. This is not to be confused with concatenated identifiers such as div . myClass { color : red ;} which applies to div elements of class myClass. The following table provides
CSS - Misplaced Pages Continue
1120-430: The separation of presentation from structure. CSS can define color, font, text alignment, size, borders, spacing, layout and many other typographic characteristics, and can do so independently for on-screen and printed views. CSS also defines non-visual styles, such as reading speed and emphasis for aural text readers. The W3C has now deprecated the use of all presentational HTML markup. For example, under pre-CSS HTML,
1155-499: The style element: All h1 elements in the document will then automatically become red without requiring any explicit code. If the author later wanted to make h1 elements blue instead, this could be done by changing the style element to: rather than by laboriously going through the document and changing the color for each individual h1 element. The styles can also be placed in an external CSS file, as described below, and loaded using syntax similar to: This further decouples
1190-418: The styles cannot be loaded or are disabled, this separation maintains the accessibility and readability of the content, ensuring that the site is usable for all users, including those with disabilities. Its multi-faceted approach, including considerations for selector specificity, rule order, and media types, ensures that websites are visually coherent and adaptive across different devices and user needs, striking
1225-639: The styling from the HTML document and makes it possible to restyle multiple documents by simply editing a shared external CSS file. CSS, or Cascading Style Sheets, offers a flexible way to style web content, with styles originating from browser defaults, user preferences, or web designers. These styles can be applied inline, within an HTML document, or through external .css files for broader consistency. Not only does this simplify web development by promoting reusability and maintainability, it also improves site performance because styles can be offloaded into dedicated .css files that browsers can cache. Additionally, even if
#277722