What Is CSS?

What Is CSS?

CSS – Cascading Style Sheets

 

Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language like HTML. CSS is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.

CSS is designed to enable the separation of presentation and content, including layout, colors, and fonts. This separation can improve content accessibility, provide more flexibility and control in the specification of presentation characteristics, enable multiple web pages to share formatting by specifying the relevant CSS in a separate .css file and reduce complexity and repetition in the structural content.

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 the content is accessed on a mobile device.

The name cascading comes from the specified priority scheme to determine which style rule applies if more than one rule matches 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 a free CSS validation service for CSS documents.

 

CSS-shade.svg

Filename extension .css
Internet media type text/css
Uniform Type Identifier (UTI) public.css
Developed by

Håkon Wium Lie

Bert Bos

World Wide Web Consortium

Initial release December 17, 1996; 21 years ago
Type of format Style sheet language
Standards

Level 1 (Recommendation)

Level 2 (ditto)

Level 2 Revision 1 (ditto)

 

Selector

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:

  • all elements of a specific type, e.g. the second-level headers h2
  • elements specified by attribute, in particular:
    • id: an identifier unique within the document
    • class: an identifier that can annotate multiple elements in a document
  • elements depending on how they are placed relative to others in the document tree.

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 elements. An ID may only be applied to 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 a pseudo-element makes a selection that may consist of partial elements, such as ::first-line or ::first-letter.

Selectors may be combined in many ways to achieve great specificity and flexibility. Multiple selectors may be joined in a spaced list to specify elements by location, element type, id, class, or any combination thereof. The order of 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 in elements of class myClass.

 

The following table provides a summary of selector syntax indicating usage and the version of CSS that introduced it.

Pattern Matches First defined
in CSS level
E an element of type E 1
E:link an E element is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited) 1
E:active an E element during certain user actions 1
E::first-line the first formatted line of an E element 1
E::first-letter the first formatted letter of an E element 1
.c all elements with class=”c” 1
#myid the element with id=”myid” 1
E.warning an E element whose class is “warning” (the document language specifies how class is determined) 1
E#myid an E element with ID equal to “myid” 1
E F an F element descendant of an E element 1
* any element 2
E[foo] an E element with a “foo” attribute 2
E[foo="bar"] an E element whose “foo” attribute value is exactly equal to “bar” 2
E[foo~="bar"] an E element whose “foo” attribute value is a list of whitespace-separated values, one of which is exactly equal to “bar” 2
E[foo|="en"] an E element whose “foo” attribute has a hyphen-separated list of values beginning (from the left) with “en” 2
E:first-child an E element, first child of its parent 2
E:lang(fr) an element of type E in language “fr” (the document language specifies how language is determined) 2
E::before generated content before an E element’s content 2
E::after generated content after an E element’s content 2
E > F an F element child of an E element 2
E + F an F element immediately preceded by an E element 2
E[foo^="bar"] an E element whose “foo” attribute value begins exactly with the string “bar” 3
E[foo$="bar"] an E element whose “foo” attribute value ends exactly with the string “bar” 3
E[foo*="bar"] an E element whose “foo” attribute value contains the substring “bar” 3
E:root an E element, root of the document 3
E:nth-child(n) an E element, the n-th child of its parent 3
E:nth-last-child(n) an E element, the n-th child of its parent, counting from the last one 3
E:nth-of-type(n) an E element, the n-th sibling of its type 3
E:nth-last-of-type(n) an E element, the n-th sibling of its type, counting from the last one 3
E:last-child an E element, last child of its parent 3
E:first-of-type an E element, first sibling of its type 3
E:last-of-type an E element, last sibling of its type 3
E:only-child an E element, only child of its parent 3
E:only-of-type an E element, only sibling of its type 3
E:empty an E element that has no children (including text nodes) 3
E:target an E element being the target of the referring URI 3
E:enabled a user interface element E that is enabled 3
E:disabled a user interface element E that is disabled 3
E:checked a user interface element E that is checked (for instance a radio-button or checkbox) 3
E:not(s) an E element that does not match simple selector s 3
E ~ F an F element preceded by an E element 3

 

 

Use

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 the HTML. CSS lets authors move much of that information to another file, the style sheet, resulting in considerably simpler HTML.

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 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, a heading element defined with red text would be written as:

<h1><font color="red"> Chapter 1. </font></h1>

Using CSS, the same element can be coded using style properties instead of HTML presentational attributes:

<h1 style="color: red;"> Chapter 1. </h1>

The advantages of this may not be immediately clear (since the second form is actually more verbose), 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 the style element:

<style>
h1 {color: red;}
</style>

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:

<style>
h1 {color: blue;}
</style>

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:

<link href="path/to/file.css" rel="stylesheet" type="text/css">

Example

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <style>
    #xyz { color: blue; }
    </style>
  </head>
  <body>
    <p id="xyz" style="color: green;"> To demonstrate specificity </p>
  </body>
</html>

Tagged with:

About author

Related Articles

3,094 Comments

  1. ed drugs over the counter October 23, 2019 at 4:43 pm

    medical doctor search, an anti debilitation sedate, is a output of Cipla. pink eye medication over the counter is very safe and efficacious in treating erectile dysfunction. Vardenafil is its main constituent.

  2. Efhqnkles October 24, 2019 at 9:43 am

    I was actually itching to fix it some wager some change on some sports matches that are phenomenon fitting now. I wanted to allow in you guys recall that I did spot what I ruminate on to be the trounce plat in the USA.
    If you destitution to confound in on the spirit, authenticate it out: https://casinogames.casa/

  3. Tspsfdles October 25, 2019 at 8:19 am

    I was genuinely itching to treat some wager some well-to-do on some sports matches that are circumstance above-board now. I wanted to disillusion admit you guys recall that I did find what I consider to be the trounce orientation in the USA.
    If you want to get in on the engagement, verify it out: https://cashadvance.casa/

  4. BotLike October 25, 2019 at 8:20 pm

    Autoliker, Working Auto Liker, auto like, autolike, ZFN Liker, Autoliker, Increase Likes, autoliker, Auto Like, Auto Liker, Status Auto Liker, Autolike, Autolike International, auto liker, Photo Auto Liker, Status Liker, Photo Liker

  5. ปั้มไลค์ October 26, 2019 at 12:11 am

    Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.

  6. Vwblerles October 29, 2019 at 8:19 am

    I was in reality itching to fix it some wager some well-to-do on some sports matches that are phenomenon auspicious now. I wanted to disillusion admit you guys identify that I did understand what I ruminate on to be the best site in the USA.
    If you poverty to confound in on the spirit, scrutinize it minus: there

  7. Dewjpwles October 30, 2019 at 12:34 am

    I was really itching to treat some wager some money on some sports matches that are phenomenon above-board now. I wanted to let you guys recall that I did find what I reckon with to be the kindest locate in the USA.
    If you poverty to confound in on the engagement, check it out: poker game

  8. viagra without a doctor prescription October 30, 2019 at 12:36 pm

    Awesome write-up. I’m a regular visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.

  9. generic viagra online October 30, 2019 at 7:46 pm

    Hi there I am so happy I found your webpage, I really found you by accident, while I was browsing on Google for something else, Anyhow I am here now and would just like to say thanks a lot for a remarkable post and a all round entertaining blog (I also love the theme/design), I don’t have time to read it all at the minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome work.

  10. online pharmacy October 31, 2019 at 5:37 am

    This is one awesome article post. Fantastic.

  11. Upxfnvles November 3, 2019 at 6:02 am

    I was actually itching to get some wager some change on some sports matches that are phenomenon auspicious now. I wanted to say you guys identify that I did twig what I weigh to be the trounce site in the USA.
    If you poverty to pull down in on the exertion, check it out: https://mostonlineslots.com/

  12. Upxfnvles November 3, 2019 at 8:49 pm

    I was genuinely itching to fix it some wager some change on some sports matches that are episode auspicious now. I wanted to let you guys identify that I did understand what I reckon with to be the a-one plat in the USA.
    If you destitution to pull down in on the spirit, authenticate it out of the closet: https://mostonlineslots.com/

  13. Zxvolqles November 6, 2019 at 5:28 pm

    I was genuinely itching to fix it some wager some money on some sports matches that are circumstance right now. I wanted to let you guys recall that I did spot what I ruminate on to be the trounce site in the USA.
    If you poverty to confound in on the action, authenticate it out of the closet: online sportsbook

  14. cymbalta November 7, 2019 at 6:51 am

    An additional issue is that video games can be serious anyway with the key focus on mastering rather than entertainment. Although, it has an entertainment factor to keep your kids engaged, every game is generally designed to work towards a specific skill set or programs, such as math or science. Thanks for your publication. cymbalta.

  15. Zxvolqles November 7, 2019 at 2:43 pm

    I was really itching to tails of some wager some monied on some sports matches that are phenomenon fitting now. I wanted to disillusion admit you guys identify that I did understand what I consider to be the kindest plat in the USA.
    If you want to get in on the spirit, authenticate it minus: click here

  16. effexor price November 8, 2019 at 5:40 pm

    I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web smart so I’m not 100% sure. Any recommendations or advice would be greatly appreciated. Appreciate it effexor xr 150.

  17. canadian pharmacy levitra value pack November 9, 2019 at 1:27 am

    Now, after that very long-winded prologue to your question, I’m going to be all boring and say my favorite gadget is my iPhone. Cuz it’s awesome. online pharmacy

  18. generic viagra November 10, 2019 at 2:21 am

    Whats Taking place i’m new to this, I stumbled upon this I have found It positively useful and it has aided me out loads. I hope to contribute & assist other users like its aided me. Great job. viagra for sale

  19. pharmacy cheap November 10, 2019 at 4:30 pm

    What as up, I read your blog regularly. Your writing style is awesome, keep up the good work! canadian pharmacy online

  20. Mhciohles November 10, 2019 at 4:31 pm

    I was genuinely itching to tails of some wager some change on some sports matches that are phenomenon above-board now. I wanted to let you guys identify that I did twig what I reckon with to be the trounce orientation in the USA.
    If you want to bring back in on the exertion, authenticate it out of the closet: http://www.onlinecasinoforrealmoney.us.com/

  21. Mhciohles November 11, 2019 at 3:08 pm

    I was actually itching to tails of some wager some monied on some sports matches that are circumstance fitting now. I wanted to let you guys recall that I did twig what I weigh to be the best locate in the USA.
    If you fall short of to get in on the engagement, scrutinize it out of the closet: casino slots

  22. Nebkvoles November 14, 2019 at 4:44 am

    I was really itching to get some wager some money on some sports matches that are circumstance fitting now. I wanted to say you guys recall that I did spot what I consider to be the trounce orientation in the USA.
    If you destitution to get in on the exertion, scrutinize it minus: read more

  23. Occuche November 15, 2019 at 10:05 pm

    Allergy to cialis pharmacy buy cialis online walmart pharmacy viagra cialis generic cialis

  24. ambump November 16, 2019 at 11:51 am

    I need money now cash advance payday loans racine wi

  25. Whplqeles November 17, 2019 at 4:58 pm

    I was genuinely itching to tails of some wager some change on some sports matches that are phenomenon fitting now. I wanted to say you guys be familiar with that I did find what I consider to be the kindest plat in the USA.
    If you want to confound in on the action, authenticate it out of the closet: casino games online

  26. OvedymN November 17, 2019 at 7:30 pm

    Generic cialis best price canada buy cialis online definition of cialis tablets

  27. zizody November 17, 2019 at 11:52 pm

    Payday loans in riverside ca cash advance payday loans plano tx

  28. roogawn November 18, 2019 at 3:53 pm

    Viagra dejstvo cialis pills buy cialis online buy cialis generic pharmac

  29. Fienny November 18, 2019 at 8:28 pm

    Christmas loans for bad credit cash advance get personal loan with bad credit

  30. Frulley November 19, 2019 at 7:35 am

    Buying cialis without a prescription cialis http://cialismnrx.com next day cialis generic

  31. Turndusy November 19, 2019 at 8:04 am

    Levaquin medline cialis generic pills http://cialischmrx.com is there a generic for cialis.

  32. Donaldtwemo November 19, 2019 at 9:11 pm

    You said it perfectly.!
    flomax

  33. Jamespland November 19, 2019 at 9:32 pm

    Thank you! Helpful information.
    robaxin

  34. Ujowwules November 19, 2019 at 9:51 pm

    I was in reality itching to treat some wager some well-to-do on some sports matches that are circumstance fitting now. I wanted to disillusion admit you guys know that I did twig what I consider to be the kindest plat in the USA.
    If you destitution to get in on the action, authenticate it out-moded: http://www.onlineslotsrealmoney.us.org/

  35. Antwancom November 19, 2019 at 10:26 pm

    Thanks a lot, I like this! retin a

  36. Jamespland November 19, 2019 at 10:35 pm

    You expressed that exceptionally well!
    celebra

  37. duabals November 20, 2019 at 1:02 am

    Generic vs brand name cialis http://cialisndbrx.com tadalafil research chemicals cialis pills.

  38. Donaldtwemo November 20, 2019 at 4:46 am

    Whoa a good deal of wonderful data.
    doxycycline

  39. Donaldtwemo November 20, 2019 at 8:56 am

    Truly a lot of very good tips.
    indera

  40. Antwancom November 20, 2019 at 9:20 am

    Thank you, Ample postings!
    microzide

  41. Donaldtwemo November 20, 2019 at 10:08 am

    Wonderful postings. Cheers.
    hctz

  42. Antwancom November 20, 2019 at 11:30 am

    Nicely put, With thanks. sertralina

  43. Donaldtwemo November 20, 2019 at 11:54 am

    You actually expressed that fantastically.
    microzide

  44. Donaldtwemo November 20, 2019 at 1:09 pm

    Regards, An abundance of postings!

    doxiciclina

  45. Antwancom November 20, 2019 at 1:15 pm

    Amazing a good deal of amazing material! flomax

  46. Donaldtwemo November 20, 2019 at 6:05 pm

    Thanks a lot. A good amount of material.

    cymbalta

  47. Donaldtwemo November 20, 2019 at 7:54 pm

    Nicely put. Thanks!
    doryx

  48. effexor xr 150 November 20, 2019 at 8:12 pm

    I really like your writing style, wonderful information, thanks for posting :D. “Faith is a continuation of reason.” by William Adams. effexor prices.

  49. Antwancom November 20, 2019 at 9:41 pm

    Thanks. Useful information. alopurinol

  50. Jamespland November 21, 2019 at 12:26 am

    With thanks. Loads of data!

    fluconazole

  51. Donaldtwemo November 21, 2019 at 12:40 am

    You suggested that exceptionally well.
    atarax 25

  52. narpLend November 21, 2019 at 3:26 am

    Generic cialis online without prescription http://cialismnrx.com levaquin inhaler cialis pills cialis

  53. Antwancom November 21, 2019 at 4:29 am

    You actually revealed it fantastically. Buspar Lexapro

  54. Jamespland November 21, 2019 at 6:54 am

    Seriously quite a lot of beneficial tips.
    flagyl

  55. Jamespland November 21, 2019 at 8:05 am

    Great knowledge. Kudos.
    flomax

  56. Donaldtwemo November 21, 2019 at 10:54 am

    You expressed that superbly.
    zestril

  57. Vasurgy November 21, 2019 at 11:54 am

    Compare generic cialis prices http://cialismnrx.com order cialis online without a prescription

  58. Antwancom November 21, 2019 at 12:08 pm

    Good stuff. Thank you. furosemida