The XHTML WYSIWYG Editor For Desktop & Web Applications

CSS Reference

FAQs

What are CSS?

CSS (Cascading Style Sheets) are a language used to attach presentation (formatting) to XHTML tags. Presentation can be visual, such as a font face or text color, or they can be used for non-visual purposes. For example, screen readers can use presentation to customize the pronunciation of text.

XHTML 1.1 only permits formatting using (referencing) CSS. XStandard for example lets business users reference the appropriate CSS by selecting styles from a drop-down menu on XStandard's toolbar, and the developer will typically tailor the selection of styles to match the type of document the user is editing.

Are CSS Industry-standard?

Yes. CSS are maintained by W3C - the same people who maintain XHTML and XML.

What Does The CSS Language Look Like?

The following is an example of a CSS syntax (or style rule) that instructs the Web browser to color all <h1> tags red:

  1. h1 {color: red}

The syntax has 3 parts: selector, property and value:

  1. selector {property: value}

The selector identifies the tags to which the style rule should apply. The property is the name of the characteristic of the XHTML tag, and the value is the measurement of that characteristic. You can assign many property / value pairs to a selector simply by inserting a semicolon between each pair. For example:

  1. h1 {color: red; font-size: 1.6 em}

Property / value pairs are called declarations. So a CSS rule has only one selector but can have one or more declarations.

How Do XHTML Documents Reference CSS?

CSS can be external (written in a separate document) or embedded (placed inside the XHTML document).

It is better to use embedded CSS when the CSS rules apply to one Web page.

It is better to use external CSS when the same CSS rules apply to more than one Web page, or if you want to be able to change the look and feel of all your Web pages at once by modifying a single CSS file.

If the CSS is external, reference it by putting a <link> tag in your XHTML document. For example:

  1. <link rel="stylesheet" href="format.css" type="text/css" />

If the CSS is embedded, reference it by putting a <style> tag in your XHTML document. For example:

  1. <style type="text/css">
  2. body {
  3. background-color: white;
  4. color: black;
  5. font-family: arial;
  6. }
  7. </style>

What Is Inline Style?

In earlier versions of XHTML, it was possible to put CSS declarations directly into HTML tags. For example:

<h1 style="color: red">Hello World!</h1>

This approach is no longer supported in XHTML 1.1 since it fuses presentation with content.

How It Works

XHTML documents contain elements (tags) that are organized into a hierarchy. Web browsers use CSS to lay out the contents of the elements and to give the contents visual formatting.

The browser draws a rectangle for each element and then lays out the element on the page inside the rectangle. There are two types of rectangle - block and inline.

This diagram show how each XHTML tag is rendered as a rectangle by a Web browser.

Block elements take up 100% of the width of their parent element. This pushes any sibling elements underneath. For example, <h1> is a block element. Any text following the <h1> element is displayed on the next line.

Inline elements take up only the width of their contents. This means that two or more inline elements can be displayed next to each other on the same line. For example, the <a> tag is an inline element. It can appear in the middle of a line with text preceding it and following it.

CSS controls the appearance of each rectangle and its contents. CSS has properties for setting foreground and background colors, border width and style, font family, font size and many more options.

Web browsers have built-in CSS for certain predefined XHTML elements. For example, the built-in CSS for headings (<h1> elements) renders text 100% larger than the regular size. The default CSS for hyperlinks (<a> elements) renders hyperlinks blue with an underline. Default CSS can be overwritten by custom CSS embedded in an XHTML document or in a separate file. Whichever option you choose, the fact that your CSS is no longer embedded inside XHTML tags means you can change the look and feel of an entire Web site quickly and simply by modifying a single CSS file.

Most Common CSS Properties

background-color

This property sets the background color of an element. For example:

  1. h1 {background-color: red}

border

This property sets the width, style and color of an element's border. For example:

  1. h1 {border: 1px solid red}

color

This property sets the foreground color of an element's content. For example:

  1. body {color: blue}

float

This property specifies if an element should float to the left, right, or not at all. The most common use of this property is to wrap text around images.

This image shows text wrapping around an element that is floating to the right.

For example:

  1. img {float: right}

font-family

This property specifies which font family to use to render the text. Since not all fonts are available on all systems, this property allows authors to specify a list of fonts. The browser will attempt to use the first font in the list that is available to the system. For example:

  1. body {font-family: arial, helvetica, sans-serif}

font-size

This property specifies the size of the font. For example:

  1. body {font-size: .8em}

font-weight

This property specifies the boldness or lightness of the text. For example:

  1. a {font-weight: bold}

margin

This property specifies the amount of space outside the border of an element.

This image shows the margin as the space outside the boder of an element.

For example:

  1. h1 {margin: 2em}

padding

This property specifies the amount of space between an element's contents and its border.

This image shows padding as the space between content and the border of an element.

For example:

  1. h1 {padding: 2em}

text-decoration

This property describes decorations to be added to the text of an element. For example:

  1. a {text-decoration: none}
  2. h1 {text-decoration: underline}

width

This property specifies the width of a block element. For example:

  1. hr {width: 90%}

Complete CSS Property Reference

 CSS Properties *
NameValuesInitial ValueApplies ToInheritedPercentagesMedia Groups
azimuth[angle] | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards | inheritcenterallyesn/aaural
background['background-color' || 'background-image' || 'background-repeat' || 'background-attachment' || 'background-position'] | inheritXXallnoallowed on 'background-position'visual
background-attachmentscroll | fixed | inheritscrollallnon/avisual
background-color[color] | transparent | inherittransparentallnon/avisual
background-image[uri] | none | inheritnoneallnon/avisual
background-position[ [[percentage] | [length] ]{1,2} | [ [top | center | bottom] || [left | center | right] ] ] | inherit0% 0%block-level and replaced elementsnorefer to the size of the box itselfvisual
background-repeatrepeat | repeat-x | repeat-y | no-repeat | inheritrepeatallnon/avisual
border[ 'border-width' || 'border-style' || [color] ] | inheritsee individual propertiesallnon/avisual
border-collapsecollapse | separate | inheritcollapse'table' and 'inline-table' elementsyesn/avisual
border-color[color]{1,4} | transparent | inheritsee individual propertiesallnon/avisual
border-spacing[length] [length]? | inherit0'table' and 'inline-table' elementsyesn/avisual
border-style[border-style]{1,4} | inheritsee individual propertiesallnon/avisual
border-top[ 'border-top-width' || 'border-style' || [color] ] | inheritsee individual propertiesallnon/avisual
border-right[ 'border-top-width' || 'border-style' || [color] ] | inheritsee individual propertiesallnon/avisual
border-bottom[ 'border-top-width' || 'border-style' || [color] ] | inheritsee individual propertiesallnon/avisual
border-left[ 'border-top-width' || 'border-style' || [color] ] | inheritsee individual propertiesallnon/avisual
border-top-color[color] | inheritthe value of the 'color' propertyallnon/avisual
border-right-color[color] | inheritthe value of the 'color' propertyallnon/avisual
border-bottom-color[color] | inheritthe value of the 'color' propertyallnon/avisual
border-left-color[color] | inheritthe value of the 'color' propertyallnon/avisual
border-top-style[border-style] | inheritnoneallnon/avisual
border-right-style[border-style] | inheritnoneallnon/avisual
border-bottom-style[border-style] | inheritnoneallnon/avisual
border-left-style[border-style] | inheritnoneallnon/avisual
border-top-width[border-width] | inheritmediumallnon/avisual
border-right-width[border-width] | inheritmediumallnon/avisual
border-bottom-width[border-width] | inheritmediumallnon/avisual
border-left-width[border-width] | inheritmediumallnon/avisual
border-width[border-width]{1,4} | inheritsee individual propertiesallnon/avisual
bottom[length] | [percentage] | auto | inheritautopositioned elementsnorefer to height of containing blockvisual
caption-sidetop | bottom | left | right | inherittoptable-caption' elementsyesn/avisual
clearnone | left | right | both | inheritnoneblock-level elementsnon/avisual
clip[shape] | auto | inheritautoblock-level and replaced elementsnon/avisual
color[color] | inheritdepends on user agentallyesn/avisual
content[ [string] | [uri] | [counter] | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inheritempty string:before and :after pseudo-elementsnon/aall
counter-increment[ [identifier] [integer]? ]+ | none | inheritnoneallnon/aall
counter-reset[ [identifier] [integer]? ]+ | none | inheritnoneallnon/aall
cue[ 'cue-before' || 'cue-after' ] | inheritXXallnon/aaural
cue-after[uri] | none | inheritnoneallnon/aaural
cue-before[uri] | none | inheritnoneallnon/aaural
cursor[ [[uri] ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize| text | wait | help ] ] | inheritautoallyesn/avisual, interactive
directionltr | rtl | inheritltrall elements, but see proseyesn/avisual
displayinline | block | list-item | run-in | compact | marker | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inheritinlineallnon/aall
elevation[angle] | below | level | above | higher | lower | inheritlevelallyesn/aaural
empty-cellsshow | hide | inheritshow'table-cell' elementsyesn/avisual
floatleft | right | none | inheritnoneall but positioned elements and generated contentnon/avisual
font[ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inheritsee individual propertiesallyesallowed on 'font-size' and 'line-height'visual
font-family[[ [family-name] | [generic-family] ],]* [[family-name] | [generic-family]] | inheritdepends on user agentallyesn/avisual
font-size[absolute-size] | [relative-size] | [length] | [percentage] | inheritmediumallyes, the computed value is inheritedrefer to parent element's font sizevisual
font-size-adjust[number] | none | inheritnoneallyesn/avisual
font-stretchnormal | wider | narrower | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inheritnormalallyesn/avisual
font-stylenormal | italic | oblique | inheritnormalallyesn/avisual
font-variantnormal | small-caps | inheritnormalallyesn/avisual
font-weightnormal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inheritnormalallyesn/avisual
height[length] | [percentage] | auto | inheritautoall elements but non-replaced inline elements, table columns, and column groupsnosee prosevisual
left[length] | [percentage] | auto | inheritautopositioned elementsnorefer to width of containing blockvisual
letter-spacingnormal | [length] | inheritnormalallyesn/avisual
line-heightnormal | [number] | [length] | [percentage] | inheritnormalallyesrefer to the font size of the element itselfvisual
list-style[ 'list-style-type' || 'list-style-position' || 'list-style-image' ] | inheritXXelements with 'display: list-itemyesn/avisual
list-style-image[uri] | none | inheritnoneelements with 'display: list-itemyesn/avisual
list-style-positioninside | outside | inheritoutsideelements with 'display: list-itemyesn/avisual
list-style-typedisc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha | upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana | katakana | hiragana-iroha | katakana-iroha | none | inheritdiscelements with 'display: list-itemyesn/avisual
margin[margin-width]{1,4} | inheritXXallnorefer to width of containing blockvisual
margin-top[margin-width] | inherit0allnorefer to width of containing blockvisual
margin-right[margin-width] | inherit0allnorefer to width of containing blockvisual
margin-bottom[margin-width] | inherit0allnorefer to width of containing blockvisual
margin-left[margin-width] | inherit0allnorefer to width of containing blockvisual
marker-offset[length] | auto | inheritautoelements with 'display: markernon/avisual
marks[ crop || cross ] | none | inheritnonepage contextN/An/avisual, paged
max-height[length] | [percentage] | none | inheritnoneall elements except non-replaced inline elements and table elementsnorefer to height of containing blockvisual
max-width[length] | [percentage] | none | inheritnoneall elements except non-replaced inline elements and table elementsnorefer to width of containing blockvisual
min-height[length] | [percentage] | inherit0all elements except non-replaced inline elements and table elementsnorefer to height of containing blockvisual
min-width[length] | [percentage] | inheritUA dependentall elements except non-replaced inline elements and table elementsnorefer to width of containing blockvisual
orphans[integer] | inherit2block-level elementsyesn/avisual, paged
outline[ 'outline-color' || 'outline-style' || 'outline-width' ] | inheritsee individual propertiesallnon/avisual, interactive
outline-color[color] | invert | inheritinvertallnon/avisual, interactive
outline-style[border-style] | inheritnoneallnon/avisual, interactive
outline-width[border-width] | inheritmediumallnon/avisual, interactive
overflowvisible | hidden | scroll | auto | inheritvisibleblock-level and replaced elementsnon/avisual
padding[padding-width]{1,4} | inheritXXallnorefer to width of containing blockvisual
padding-top[padding-width] | inherit0allnorefer to width of containing blockvisual
padding-right[padding-width] | inherit0allnorefer to width of containing blockvisual
padding-bottom[padding-width] | inherit0allnorefer to width of containing blockvisual
padding-left[padding-width] | inherit0allnorefer to width of containing blockvisual
page[identifier] | autoautoblock-level elementsyesn/avisual, paged
page-break-afterauto | always | avoid | left | right | inheritautoblock-level elementsnon/avisual, paged
page-break-beforeauto | always | avoid | left | right | inheritautoblock-level elementsnon/avisual, paged
page-break-insideavoid | auto | inheritautoblock-level elementsyesn/avisual, paged
pause[ [[time] | [percentage]]{1,2} ] | inheritdepends on user agentallnosee descriptions of 'pause-before' and 'pause-afteraural
pause-after[time] | [percentage] | inheritdepends on user agentallnosee proseaural
pause-before[time] | [percentage] | inheritdepends on user agentallnosee proseaural
pitch[frequency] | x-low | low | medium | high | x-high | inheritmediumallyesn/aaural
pitch-range[number] | inherit50allyesn/aaural
play-during[uri] mix? repeat? | auto | none | inheritautoallnon/aaural
positionstatic | relative | absolute | fixed | inheritstaticall elements, but not to generated contentnon/avisual
quotes[[string] [string]]+ | none | inheritdepends on user agentallyesn/avisual
richness[number] | inherit50allyesn/aaural
right[length] | [percentage] | auto | inheritautopositioned elementsnorefer to width of containing blockvisual
size[length]{1,2} | auto | portrait | landscape | inheritautothe page contextN/An/avisual, paged
speaknormal | none | spell-out | inheritnormalallyesn/aaural
speak-headeronce | always | inheritonceelements that have table header informationyesn/aaural
speak-numeraldigits | continuous | inheritcontinuousallyesn/aaural
speak-punctuationcode | none | inheritnoneallyesn/aaural
speech-rate[number] | x-slow | slow | medium | fast | x-fast | faster | slower | inheritmediumallyesn/aaural
stress[number] | inherit50allyesn/aaural
table-layoutauto | fixed | inheritautotable' and 'inline-table' elementsnon/avisual
text-alignleft | right | center | justify | [string] | inheritdepends on user agent and writing directionblock-level elementsyesn/avisual
text-decorationnone | [ underline || overline || line-through || blink ] | inheritnoneallno (see prose)n/avisual
text-indent[length] | [percentage] | inherit0block-level elementsyesrefer to width of containing blockvisual
text-shadownone | [[color] || [length] [length] [length]? ,]* [[color] || [length] [length] [length]?] | inheritnoneallno (see prose)n/avisual
text-transformcapitalize | uppercase | lowercase | none | inheritnoneallyesn/avisual
top[length] | [percentage] | auto | inheritautopositioned elementsnorefer to height of containing blockvisual
unicode-bidinormal | embed | bidi-override | inheritnormalall elements, but see prosenon/avisual
vertical-alignbaseline | sub | super | top | text-top | middle | bottom | text-bottom | [percentage] | [length] | inheritbaselineinline-level and 'table-cell' elementsnorefer to the 'line-height' of the element itselfvisual
visibilityvisible | hidden | collapse | inheritinheritallnon/avisual
voice-family[[[specific-voice] | [generic-voice] ],]* [[specific-voice] | [generic-voice] ] | inheritdepends on user agentallyesn/aaural
volume[number] | [percentage] | silent | x-soft | soft | medium | loud | x-loud | inheritmediumallyesrefer to inherited valueaural
white-spacenormal | pre | nowrap | inheritnormalblock-level elementsyesn/avisual
widows[integer] | inherit2block-level elementsyesn/avisual, paged
width[length] | [percentage] | auto | inheritautoall elements but non-replaced inline elements, table rows, and row groupsnorefer to width of containing blockvisual
word-spacingnormal | [length] | inheritnormalallyesn/avisual
z-indexauto | [integer] | inheritautopositioned elementsnon/avisual

* Original W3C document. Copyright (c) World Wide Web Consortium, (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved.