Positioning

display

The display property specifies the display behavior (the type of rendering box) of an element.

In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet. The default value in XML is inline, including SVG elements.

Note: The values "flex" and "inline-flex" requires the -webkit- prefix to work in Safari.

Note: "display: contents" does not work in Edge prior version 79.

display: inline

 

ValueDescription
inlineDisplays an element as an inline element (like <span>). Any height and width properties will have no effect
blockDisplays an element as a block element (like <p>). It starts on a new line, and takes up the whole width
contentsMakes the container disappear, making the child elements children of the element the next level up in the DOM
flexDisplays an element as a block-level flex container
gridDisplays an element as a block-level grid container
inline-blockDisplays an element as an inline-level block container. The element itself is formatted as an inline element, but you can apply height and width values
inline-flexDisplays an element as an inline-level flex container
inline-gridDisplays an element as an inline-level grid container
inline-tableThe element is displayed as an inline-level table
list-itemLet the element behave like a <li> element
run-inDisplays an element as either block or inline, depending on context
tableLet the element behave like a <table> element
table-captionLet the element behave like a <caption> element
table-column-groupLet the element behave like a <colgroup> element
table-header-groupLet the element behave like a <thead> element
table-footer-groupLet the element behave like a <tfoot> element
table-row-groupLet the element behave like a <tbody> element
table-cellLet the element behave like a <td> element
table-columnLet the element behave like a <col> element
table-rowLet the element behave like a <tr> element
noneThe element is completely removed
align-content

The align-content property modifies the behavior of the flex-wrap property. It is similar to align-items, but instead of aligning flex items, it aligns flex lines.

Note: There must be multiple lines of items for this property to have any effect!

Tip: Use the justify-content property to align the items on the main-axis (horizontally).

align-content: center

 

ValueDescription
stretchDefault value. Lines stretch to take up the remaining space
centerLines are packed toward the center of the flex container
flex-startLines are packed toward the start of the flex container
flex-endLines are packed toward the end of the flex container
space-betweenLines are evenly distributed in the flex container
space-aroundLines are evenly distributed in the flex container, with half-size spaces on either end
space-evenlyLines are evenly distributed in the flex container, with equal space around them
align-items

The align-items property specifies the default alignment for items inside the flexible container.

Tip: Use the align-self property of each item to override the align-items property.

align-items: center

 

ValueDescription
stretchDefault. Items are stretched to fit the container
centerItems are positioned at the center of the container
flex-startItems are positioned at the beginning of the container
flex-endItems are positioned at the end of the container
baselineItems are positioned at the baseline of the container
align-self

The align-self property specifies the alignment for the selected item inside the flexible container.

Note: The align-self property overrides the flexible container's align-items property.

align-self: center

 

ValueDescription
autoDefault. The element inherits its parent container's align-items property, or "stretch" if it has no parent container
stretchThe element is positioned to fit the container
centerThe element is positioned at the center of the container
flex-startThe element is positioned at the beginning of the container
flex-endThe element is positioned at the end of the container
baselineThe element is positioned at the baseline of the container
justify-content

The justify-content property aligns the flexible container's items when the items do not use all available space on the main-axis (horizontally).

Tip: Use the align-items property to align the items vertically.

justify-content: center

 

ValueDescription
flex-startDefault value. Items are positioned at the beginning of the container
flex-endItems are positioned at the end of the container
centerItems are positioned in the center of the container
space-betweenItems will have space between them
space-aroundItems will have space before, between, and after them
space-evenlyItems will have equal space around them
position

The position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky).

Note: The sticky value is not supported in Internet Explorer or Edge 15 and earlier versions.

position: absolute

 

ValueDescription
staticDefault value. Elements render in order, as they appear in the document flow
absoluteThe element is positioned relative to its first positioned (not static) ancestor element
fixedThe element is positioned relative to the browser window
relativeThe element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position
stickyThe element is positioned based on the user's scroll position
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).
Note: Not supported in IE/Edge 15 or earlier. Supported in Safari from version 6.1 with a -webkit- prefix.
clip

What happens if an image is larger than its containing element?

The clip property lets you specify a rectangle to clip an absolutely positioned element. The rectangle is specified as four coordinates, all from the top-left corner of the element to be clipped.

Note: The clip property does not work if "overflow:visible".

Note: The clip property is deprecated and will be replaced by the clip-path property in the future.

clip: rect(0px,60px,200px,0px)

 

ValueDescription
autoNo clipping will be applied. This is default
shapeClips an element. The only valid value is: rect (top, right, bottom, left)
perspective

The perspective property is used to give a 3D-positioned element some perspective.

The perspective property defines how far the object is away from the user. So, a lower value will result in a more intensive 3D effect than a higher value.

When defining the perspective property for an element, it is the CHILD elements that get the perspective view, NOT the element itself.

Tip: Also look at the perspective-origin property, which defines at which position the user is looking at the 3D object.

perspective: 100px

 

ValueDescription
lengthHow far the element is placed from the view
noneDefault value. Same as 0. The perspective is not set
perspective-origin

The perspective-origin property defines at from which position the user is looking at the 3D-positioned element.

When defining the perspective-origin property for an element, it is the CHILD elements that will get the effect, NOT the element itself.

Note: This property must be used in conjunction with the perspective property!

perspective-origin: left

 

ValueDescription
x-axisDefining where the view is placed at the x-axis
Possible values: left, center, right, length, %
Default value: 50%
y-axisDefining where the view is placed at the y-axis
Possible values: top, center, bottom, length, %
Default value: 50%
order

The order property specifies the order of a flexible item relative to the rest of the flexible items inside the same container.

Note: If the element is not a flexible item, the order property has no effect.

div#myRedDIV {order: 2;}

div#myBlueDIV {order: 4;}

div#myGreenDIV {order: 3;}

div#myPinkDIV {order: 1;}

 

ValueDescription
numberDefault value 0. Specifies the order for the flexible item
float

The float property specifies whether an element should float to the left, right, or not at all.

Note: Absolutely positioned elements ignore the float property!

Note: Elements next to a floating element will flow around it. To avoid this, use the clear property or the clearfix hack (see example at the bottom of this page).

float: right

 

ValueDescription
noneThe element does not float, (will be displayed just where it occurs in the text). This is default
leftThe element floats to the left of its container
rightThe element floats the right of its container
clear

The clear property controls the flow next to floated elements.

The clear property specifies what should happen with the element that is next to a floating element.

clear: left

 

ValueDescription
noneDefault. The element is not pushed below left or right floated elements
leftThe element is pushed below left floated elements
rightThe element is pushed below right floated elements
bothThe element is pushed below both left and right floated elements
object-position

The object-position property is used together with object-fit to specify how an <img> or <video> should be positioned with x/y coordinates inside its "own content box".

object-fit: none;

object-position: 5px 10%;

 

ValueDescription
positionSpecifies the position of the image or video inside its content box. First value controls the x-axis and the second value controls the y-axis. Can be a string (left, center or right), or a number (in px or %). Negative values are allowed
vertical-align

The vertical-align property sets the vertical alignment of an element.

vertical-align: sub

 

ValueDescription
baselineThe element is aligned with the baseline of the parent. This is default
lengthRaises or lower an element by the specified length. Negative values are allowed. Read about length units
%Raises or lower an element by a percent of the "line-height" property. Negative values are allowed
subThe element is aligned with the subscript baseline of the parent
superThe element is aligned with the superscript baseline of the parent
topThe element is aligned with the top of the tallest element on the line
text-topThe element is aligned with the top of the parent element's font
middleThe element is placed in the middle of the parent element
bottomThe element is aligned with the lowest element on the line
text-bottomThe element is aligned with the bottom of the parent element's font
z-index

The z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).

Note: If two positioned elements overlap without a z-index specified, the element positioned last in the HTML code will be shown on top.

z-index: -1;

 

ValueDescription
autoSets the stack order equal to its parents. This is default
numberSets the stack order of the element. Negative numbers are allowed
top

The top property affects the vertical position of a positioned element. This property has no effect on non-positioned elements.

  • If position: absolute; or position: fixed; - the top property sets the top edge of an element to a unit above/below the top edge of its nearest positioned ancestor.

  • If position: relative; - the top property makes the element's top edge to move above/below its normal position.

  • If position: sticky; - the top property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.

  • If position: static; - the top property has no effect.

top: 50px;

 

ValueDescription
autoLets the browser calculate the top edge position. This is default
lengthSets the top edge position in px, cm, etc. Negative values are allowed.
%Sets the top edge position in % of containing element. Negative values are allowed
bottom

The bottom property affects the vertical position of a positioned element. This property has no effect on non-positioned elements.

  • If position: absolute; or position: fixed; - the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor.

  • If position: relative; - the bottom property makes the element's bottom edge to move above/below its normal position.

  • If position: sticky; - the bottom property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.

  • If position: static; - the bottom property has no effect.

bottom: 10px;

 

ValueDescription
autoLets the browser calculate the top edge position. This is default
lengthSets the top edge position in px, cm, etc. Negative values are allowed.
%Sets the top edge position in % of containing element. Negative values are allowed
left

The left property affects the horizontal position of a positioned element. This property has no effect on non-positioned elements.

  • If position: absolute; or position: fixed; - the left property sets the left edge of an element to a unit to the left of the left edge of its nearest positioned ancestor.

  • If position: relative; - the left property sets the left edge of an element to a unit to the left/right of its normal position.

  • If position: sticky; - the left property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.

  • If position: static; - the left property has no effect.

left: 150px;

 

ValueDescription
autoLets the browser calculate the top edge position. This is default
lengthSets the top edge position in px, cm, etc. Negative values are allowed.
%Sets the top edge position in % of containing element. Negative values are allowed

Spacing

margin

The margin property sets the margins for an element, and is a shorthand property for the following properties:

  • • margin-top

  • • margin-right

  • • margin-bottom

  • • margin-left

If the margin property has four values:

margin: 10px 5px 15px 20px;

  • top margin is 10px

  • right margin is 5px

  • bottom margin is 15px

  • left margin is 20px

If the margin property has three values:

margin: 10px 5px 15px;

  • top margin is 10px

  • right and left margins are 5px

  • bottom margin is 15px

If the margin property has two values:

margin: 10px 5px;

  • top and bottom margins are 10px

  • right and left margins are 5px

If the margin property has one value:

margin: 10px;

  • all four margins are 10px

ValueDescription
lengthSpecifies a margin in px, pt, cm, etc. Default value is 0. Negative values are allowed. Read about length units
%Specifies a margin in percent of the width of the containing element
autoThe browser calculates a margin
padding

An element's padding is the space between its content and its border.

The padding property is a shorthand property for:

  • padding-top

  • padding-right

  • padding-bottom

  • padding-left

Note: Padding creates extra space within an element, while margin creates extra space around an element.

If the padding property has four values:

padding:10px 5px 15px 20px;

  • top padding is 10px

  • right padding is 5px

  • bottom padding is 15px

  • left padding is 20px

If the padding property has three values:

padding:10px 5px 15px;

  • top padding is 10px

  • right and left padding are 5px

  • bottom padding is 15px

If the padding property has two values:

padding:10px 5px;

  • top and bottom padding are 10px

  • right and left padding are 5px

If the padding property has one value:

padding:10px;

  • all four paddings are 10px

 

ValueDescription
lengthSpecifies the padding in px, pt, cm, etc. Default value is 0. Read about length units
%Specifies the padding in percent of the width of the containing element
break-after

The break-after property specifies whether or not a page break, column break, or region break should occur after the specified element.

The break-after property extends the CSS2 page-break-after property.

Using break-after, you can tell the browser to break the page, column, or region after the element the break-afterproperty is applied to, or avoid the element to be split and span across two pages.

break-after: always;

 

ValueDescription
autoDefault. Automatic page/column/region break after the element
allAlways insert a page-break right after the principal box
alwaysAlways insert a page-break after the element
avoidAvoid a page/column/region break after the element
avoid-columnAvoid a column-break after the element
avoid-pageAvoid a page-break after the element
avoid-regionAvoid a region-break after the element
columnAlways insert a column-break after the element
leftInsert one or two page-breaks after the element so that the next page is formatted as a left page
pageAlways insert a page-break after the element
rectoInsert one or two page-breaks after the principal box so that the next page is formatted as a recto page
regionAlways insert a region-break after the element
rightInsert one or two page-breaks after the element so that the next page is formatted as a right page
versoInsert one or two page-breaks after the principal box so that the next page is formatted as a verso page
break-before

The break-before property specifies whether or not a page break, column break, or region break should occur before the specified element.

The break-before property extends the CSS2 page-break-before property.

Using break-before, you can tell the browser to break the page, column, or region before the element the break-before property is applied to, or avoid the element to be split and span across two pages.

break-before: always;

 

ValueDescription
autoDefault. Automatic page/column/region break before the element
allAlways insert a page-break right before the principal box
alwaysAlways insert a page-break before the element
avoidAvoid a page/column/region break before the element
avoid-columnAvoid a column-break before the element
avoid-pageAvoid a page-break before the element
avoid-regionAvoid a region-break before the element
columnAlways insert a column-break before the element
leftInsert one or two page-breaks before the element so that the next page is formatted as a left page
pageAlways insert a page-break before the element
rectoInsert one or two page-breaks before the principal box so that the next page is formatted as a recto page
regionAlways insert a region-break before the element
rightInsert one or two page-breaks before the element so that the next page is formatted as a right page
versoInsert one or two page-breaks before the principal box so that the next page is formatted as a verso page
break-inside

The break-inside property specifies whether or not a page break, column break, or region break should occur inside the specified element.

The break-inside property extends then CSS2 page-break-inside property.

With break-inside, you can tell the browser to avoid breaks inside images, code snippets, tables, and listst.

ValueDescription
autoDefault. Automatic page/column/region break inside the element
avoidAvoid a page/column/region break inside the element
avoid-columnAvoid a column-break inside the element
avoid-pageAvoid a page-break inside the element
avoid-regionAvoid a region-break inside the element
page-break-after

The page-break-after property adds a page-break after a specified element.

Tip:The properties: page-break-before, page-break-after and page-break-inside help to define how a document should behave when printed.

Note:You cannot use this property on an empty <div> or on absolutely positioned elements.

page-break-after: always;

 

ValueDescription
autoDefault. Automatic page-break
alwaysAlways insert a page-break after the element
avoidAvoid a page-break after the element (if possible)
leftInsert page-break after the element so that the next page is formatted as a left page
rightInsert page-break after the element so that the next page is formatted as a right page
page-break-before

The page-break-before property adds a page-break before a specified element..

Tip: The properties: page-break-before, page-break-after and page-break-inside help to define how a document should behave when printed.

Note: You cannot use this property on an empty <div> or on absolutely positioned elements.

Note: None of the browsers support "avoid".

Note: Browsers may interpret "left" and "right" as "always".

page-break-before: always;

 

ValueDescription
autoDefault. Automatic page-breaks
alwaysAlways insert a page-break before the element
avoidAvoid page-break before the element (if possible)
leftInsert page-break before the element so that the next page is formatted as a left page
rightInsert page-break before the element so that the next page is formatted as a right page
page-break-inside

The page-break-inside property sets whether a page-break should be avoided inside a specified element.

Tip: The properties: page-break-before, page-break-after and page-break-inside help to define how a document should behave when printed.

Note: You cannot use this property on absolutely positioned elements.

page-break-inside: avoid;

 

ValueDescription
autoDefault. Automatic page-breaks
avoidAvoid page-break inside the element (if possible)
widows

The widows property specifies the minimum number of lines that must be left at the top of a page or column.

widows: 2;

 

ValueDescription
integerSpecifies the minimum number of lines that must be left at the top of a page or column. Negative values are not allowed
orphans

The orphans property specifies the minimum number of lines that must be left at the bottom of a page or column.

orphans: 4;

 

ValueDescription
integerSpecifies the minimum number of lines that must be left at the bottom of a page or column. Negative values are not allowed

Sizing

flex

The flex property is a shorthand property for:

  • • flex-grow

  • • flex-shrink

  • • flex-basis

The flex property sets the flexible length on flexible items.

Note: If the element is not a flexible item, the flex property has no effect.

flex: 1 8 2;

 

ValueDescription
autoSame as 1 1 auto.
initialSame as 0 1 auto.
noneSame as 0 0 auto.
flex-grow

The flex-grow property specifies how much the item will grow relative to the rest of the flexible items inside the same container.

Note: If the element is not a flexible item, the flex-grow property has no effect.

flex-grow: 1;

 

ValueDescription
numberA number specifying how much the item will grow relative to the rest of the flexible items. Default value is 0
flex-shrink

The flex-shrink property specifies how the item will shrink relative to the rest of the flexible items inside the same container.

flex-shrink: 3;

 

ValueDescription
numberA number specifying how much the item will shrink relative to the rest of the flexible items. Default value is 1
flex-basis

The flex-basis property specifies the initial length of a flexible item.

Note: If the element is not a flexible item, the flex-basis property has no effect.

flex-basis: 100px;

 

ValueDescription
numberA length unit, or percentage, specifying the initial length of the flexible item(s)
autoDefault value. The length is equal to the length of the flexible item. If the item has no length specified, the length will be according to its content
flex-flow

The flex-flow property is a shorthand property for:

  • flex-direction

  • flex-wrap

Note: If the elements are not flexible items, the flex-flow property has no effect.

flex-flow: row-reverse wrap;

flex-direction

The flex-direction property specifies the direction of the flexible items.

Note: If the element is not a flexible item, the flex-direction property has no effect.

flex-direction: row-reverse;

 

ValueDescription
rowDefault value. The flexible items are displayed horizontally, as a row
row-reverseSame as row, but in reverse order
columnThe flexible items are displayed vertically, as a column
column-reverseSame as column, but in reverse order
flex-wrap

The flex-wrap property specifies whether the flexible items should wrap or not.

Note: If the elements are not flexible items, the flex-wrap property has no effect.

flex-wrap: wrap

 

ValueDescription
nowrapDefault value. Specifies that the flexible items will not wrap
wrapSpecifies that the flexible items will wrap if necessary
wrap-reverseSpecifies that the flexible items will wrap, if necessary, in reverse order
height

The height property sets the height of an element.

The height of an element does not include padding, borders, or margins!

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly.

If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow. How the container will handle the overflowing content is defined by the overflow property.

Note: The min-height and max-height properties override the height property.

height: 50px;

 

ValueDescription
autoThe browser calculates the height. This is default
lengthDefines the height in px, cm, etc.
%Defines the height in percent of the containing block
width

The width property sets the width of an element.

The width of an element does not include padding, borders, or margins!

Note: The min-width and max-width properties override the width property.

width: 150px;

 

ValueDescription
autoThe browser calculates the height. This is default
lengthDefines the height in px, cm, etc.
%Defines the height in percent of the containing block
max-height

The max-height property defines the maximum height of an element.

If the content is larger than the maximum height, it will overflow. How the container will handle the overflowing content is defined by the overflow property.

If the content is smaller than the maximum height, the max-height property has no effect.

Note: This prevents the value of the height property from becoming larger than max-height. The value of the max-height property overrides the height property.

max-height: 50px;

 

ValueDescription
noneNo maximum height. This is default
lengthDefines the maximum height in px, cm, etc.
%Defines the maximum height in percent of the containing block
max-width

The max-width property defines the maximum width of an element.

If the content is larger than the maximum width, it will automatically change the height of the element.

If the content is smaller than the maximum width, the max-width property has no effect.

Note: This prevents the value of the width property from becoming larger than max-width. The value of the max-widthproperty overrides the width property.

max-width: 150px;

 

ValueDescription
noneNo maximum width. This is default
lengthDefines the maximum width in px, cm, etc.
%Defines the maximum width in percent of the containing block
min-height

The min-height property defines the minimum height of an element.

If the content is smaller than the minimum height, the minimum height will be applied.

If the content is larger than the minimum height, the min-height property has no effect.

Note: This prevents the value of the height property from becoming smaller than min-height.

min-height: 200px;

 

ValueDescription
lengthDefault value is 0. Defines the minimum height in px, cm, etc. Read about length units
%Defines the minimum height in percent of the containing block
min-width

The min-width property defines the minimum width of an element.

If the content is smaller than the minimum width, the minimum width will be applied.

If the content is larger than the minimum width, the min-width property has no effect.

Note: This prevents the value of the width property from becoming smaller than min-width.

min-width: 500px;

 

ValueDescription
lengthDefault value is 0. Defines the minimum width in px, cm, etc. Read about length units
%Defines the minimum width in percent of the containing block
box-sizing

The box-sizing property defines how the width and height of an element are calculated: should they include padding and borders, or not.

box-sizing: border-box;

 

ValueDescription
content-boxDefault. The width and height properties (and min/max properties) includes only the content. Border and padding are not included
border-boxThe width and height properties (and min/max properties) includes content, padding and border
object-fit

The object-fit property is used to specify how an <img> or <video> should be resized to fit its container.

This property tells the content to fill the container in a variety of ways; such as "preserve that aspect ratio" or "stretch up and take up as much space as possible".

object-fit: cover;

 

ValueDescription
fillThis is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit
containThe replaced content is scaled to maintain its aspect ratio while fitting within the element's content box
coverThe replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit
noneThe replaced content is not resized
scale-downThe content is sized as if none or contain were specified (would result in a smaller concrete object size)
resize

The resize property defines if (and how) an element is resizable by the user.

Note: The resize property does not apply to inline elements or to block elements where overflow="visible". So, make sure that overflow is set to "scroll", "auto", or "hidden".

resize: both;

 

ValueDescription
noneDefault value. The user cannot resize the element
bothThe user can resize both the height and width of the element
horizontalThe user can resize the width of the element
verticalThe user can resize the height of the element

Columns, Grids & Tables

columns

The columns property is a shorthand property for:

  • column-width

  • column-count

columns: 100px 3;

 

ValueDescription
column-widthDefines the minimum width for each column
column-countDefines the maximum number of columns
column-width

The column-width property specifies the column width.

The number of columns will be the minimum number of columns needed to show all the content across the element.

column-width is a flexible property. Think of column-width as a minimum width suggestion for the browser. Once the browser cannot fit at least two columns at your specified width then the columns will stop and drop into a single column.

column-width: 100px;

 

ValueDescription
autoDefault value. The column width will be determined by the browser
lengthA length that specifies the width of the columns. The number of columns will be the minimum number of columns needed to show all the content across the element. Read about length units
column-count

The column-count property specifies the number of columns an element should be divided into.

column-count: 3;

 

ValueDescription
numberThe optimal number of columns into which the content of the element will be flowed
autoDefault value. The number of columns will be determined by other properties, like e.g. "column-width"
column-rule

The column-rule property sets the width, style, and color of the rule between columns.

This property is a shorthand property for:

  • column-rule-width

  • column-rule-style (required)

  • column-rule-color

If column-rule-color is omitted, the color applied will be the color of the text.

column-rule: 4px double #ff00ff;

column-rule-width

The column-rule-width property specifies the width of the rule between columns.

column-rule-width: 10px;

 

ValueDescription
mediumDefault value. Defines a medium rule
thinDefines a thin rule
thickDefines a thick rule
lengthSpecifies the width of the rule
column-rule-style

The column-rule-style property specifies the style of the rule between columns.

column-rule-style: dotted;

 

ValueDescription
noneDefault value. Defines no rule
hiddenDefines a hidden rule
dottedDefines a dotted rule
dashedDefines a dashed rule
solidDefines a solid rule
doubleDefines a double rule
grooveSpecifies a 3D grooved rule. The effect depends on the width and color values
ridgeSpecifies a 3D ridged rule. The effect depends on the width and color values
insetSpecifies a 3D inset rule. The effect depends on the width and color values
outsetSpecifies a 3D outset rule. The effect depends on the width and color values
column-rule-color

The column-rule-color property specifies the color of the rule between columns.

column-rule-color: #ff0000;

 

ValueDescription
colorSpecifies the color of the rule. Look at CSS Color Values for a complete list of possible color values
column-fill

The column-fill property specifies how to fill columns, balanced or not.

Tip: If you add a height to a multi-column element, you can control how the content fills the columns. The content can be balanced or filled sequentially.

column-fill: balance;

 

ValueDescription
balanceDefault value. Fills each column with about the same amount of content, but will not allow the columns to be taller than the height (so, columns might be shorter than the height as the browser distributes the content evenly horizontally)
autoFills each column until it reaches the height, and do this until it runs out of content (so, this value will not necessarily fill all the columns nor fill them evenly)
column-gap

The column-gap property specifies the gap between the columns.

Note: If there is a column-rule between columns, it will appear in the middle of the gap.

column-gap: 40px;

 

ValueDescription
lengthA specified length that will set the gap between the columns
normalDefault value. Specifies a normal gap between the columns. W3C suggests a value of 1em
column-span

The column-span property specifies how many columns an element should span across.

column-span: all;

 

ValueDescription
noneDefault value. The element should span across one column
allThe element should span across all columns
table-layout

The table-layout property defines the algorithm used to lay out table cells, rows, and columns.

Tip: The main benefit of table-layout: fixed; is that the table renders much faster. On large tables, users will not see any part of the table until the browser has rendered the whole table. So, if you use table-layout: fixed, users will see the top of the table while the browser loads and renders rest of the table. This gives the impression that the page loads a lot quicker!

table-layout: fixed;

 

ValueDescription
autoBrowsers use an automatic table layout algorithm. The column width is set by the widest unbreakable content in the cells. The content will dictate the layout
fixedSets a fixed table layout algorithm. The table and column widths are set by the widths of table and col or by the width of the first row of cells. Cells in other rows do not affect column widths. If no widths are present on the first row, the column widths are divided equally across the table, regardless of content inside the cells
grid

The grid property is a shorthand property for:

  • grid-template-rows

  • grid-template-columns

  • grid-template-areas

  • grid-auto-rows

  • grid-auto-columns

  • grid-auto-flow

grid: 150px / auto auto auto;

grid-template

The grid-template property is a shorthand property for the following properties:

  • grid-template-rows

  • grid-template-columns

  • grid-template-areas

grid-template: 150px / auto auto auto;

grid-template-rows

The grid-template-rows property specifies the number (and the heights) of the rows in a grid layout.

The values are a space-separated list, where each value specifies the height of the respective row.

grid-template-rows: 100px 300px;

 

ValueDescription
noneNo size is set. Rows are created if needed
autoThe size of the rows is determined by the size of the container, and on the size of the content of the items in the row
max-contentSets the size of each row to depend on the largest item in the row
min-contentSets the size of each row to depend on the smallest item in the row
lengthSets the size of the rows, by using a legal length value. Read about length units
grid-template-columns

The grid-template-columns property specifies the number (and the widths) of columns in a grid layout.

The values are a space separated list, where each value specifies the size of the respective column.

grid-template-columns: auto auto auto auto;

 

ValueDescription
noneDefault value. Columns are created if needed
autoThe size of the columns is determined by the size of the container and on the size of the content of the items in the column
max-contentSets the size of each column to depend on the largest item in the column
min-contentSets the size of each column to depend on the smallest item in the column
lengthSets the size of the columns, by using a legal length value. Read about length units
grid-template-areas

The grid-template-areas property specifies areas within the grid layout.

You can name grid items by using the grid-area property, and then reference to the name in the grid-template-areasproperty.

Each area is defined by apostrophes. Use a period sign to refer to a grid item with no name.

grid-template-areas: "myArea myArea . . .";

 

ValueDescription
noneDefault value. No named grid areas
itemnamesA sequence that specifies how each columns and row should display
grid-auto-rows

The grid-auto-rows property sets a size for the rows in a grid container.

This property affects only rows with the size not set.

grid-auto-rows: 150px;

 

ValueDescription
autoDefault value. The size of the rows is determined by the size of the largest item in the row
max-contentSets the size of each row to depend on the largest item in the row
min-contentSets the size of each row to depend on the largest item in the row
lengthSets the size of the rows, by using a legal length value. Read about length units
grid-auto-columns

The grid-auto-columns property sets a size for the columns in a grid container.

This property affects only columns with the size not set.

grid-auto-columns: 50px;

 

ValueDescription
autoDefault value. The size of the columns is determined by the size of the container
fit-content()
max-contentSets the size of each column depending on the largest item in the column
min-contentSets the size of each column depending on the smallest item in the column
minmax(min.max)Sets a size range greater than or equal to min and less than or equal to max
lengthSets the size of the columns, by using a legal length value. Read about length units
%Sets the size of the columns, by using a percent value
grid-auto-flow

The grid-auto-flow property controls how auto-placed items get inserted in the grid.

grid-auto-flow: column;

 

ValueDescription
rowDefault value. Places items by filling each row
columnPlaces items by filling each column
densePlace items to fill any holes in the grid
row densePlaces items by filling each row, and fill any holes in the grid
column densePlaces items by filling each column, and fill any holes in the grid
grid-area

The grid-area property specifies a grid item's size and location in a grid layout, and is a shorthand property for the following properties:

  • grid-row-start

  • grid-column-start

  • grid-row-end

  • grid-column-end

The grid-area property can also be used to assign a name to a grid item. Named grid items can then be referenced to by the grid-template-areas property of the grid container. See examples below.

grid-area: 2 / 1 / span 2 / span 3;

grid-area: myArea;

grid-row

The grid-row property specifies a grid item's size and location in a grid layout, and is a shorthand property for the following properties:

  • grid-row-start

  • grid-row-end

grid-row: 1 / span 2;

grid-row-start

The grid-row-start property defines on which row-line the item will start.

grid-row-start: 2;

 

ValueDescription
autoDefault value. The item will be placed by following the flow.
row-lineSpecifies on which row to start the display of the item.
grid-row-end

The grid-row-end property defines how many rows an item will span, or on which row-line the item will end (see example at the end of this page).

grid-row-end: span 3;

 

ValueDescription
autoDefault value. The item will span one row.
span nSpecifies the number of rows the item will span.
row-lineSpecifies on which row to end the display of the item.
grid-column

The grid-column property specifies a grid item's size and location in a grid layout, and is a shorthand property for the following properties:

  • grid-column-start

  • grid-column-end

grid-column: 1 / span 2;

grid-column-start

The grid-column-start property defines on which column-line the item will start.

grid-column-start: 2;

 

ValueDescription
autoDefault value. The item will be placed following the flow
span nSpecifies the number of columns the item will span
column-lineSpecifies on which column to start the display of the item
grid-column-end

The grid-column-end property defines how many columns an item will span, or on which column-line the item will end (see example at the end of this page).

grid-column-end: span 3;

 

ValueDescription
autoDefault value. The item will span one column
span nSpecifies the number of columns the item will span
column-lineSpecifies on which column to end the display of the item
grid-gap

The grid-gap property defines the size of the gap between the rows and columns in a grid layout, and is a shorthand property for the following properties:

  • grid-row-gap

  • grid-column-gap

Note: This property was renamed to gap in CSS3.

grid-gap: 50px;

grid-row-gap

The grid-row-gap property defines the size of the gap between the rows in a grid layout.

Note: This property was renamed to row-gap in CSS3.

grid-row-gap: 50px;

 

ValueDescription
lengthAny legal length value, like px or %. 0 is the default value
grid-column-gap

The grid-column-gap property defines the size of the gap between the columns in a grid layout.

Note: This property was renamed to column-gap in CSS3.

grid-column-gap: 50px;

 

ValueDescription
lengthAny legal length value, like px or %. 0 is the default value
empty-cells

The empty-cells property sets whether or not to display borders on empty cells in a table.

Note: This property has no effect if border-collapse is "collapse".

empty-cells: hide;

 

ValueDescription
showDisplay borders on empty cells. This is default
hideHide borders on empty cells
border-collapse

The border-collapse property sets whether table borders should collapse into a single border or be separated as in standard HTML.

border-collapse: collapse;

 

ValueDescription
separateBorders are separated; each cell will display its own borders. This is default.
collapseBorders are collapsed into a single border when possible (border-spacing and empty-cells properties have no effect)
border-spacing

The border-spacing property sets the distance between the borders of adjacent cells.

Note:Note: This property works only when border-collapse is separate.

border-spacing: 15px 50px;

 

ValueDescription
length lengthSpecifies the distance between the borders of adjacent cells in px, cm, etc. Negative values are not allowed.
If one value is specified, it defines both the horizontal and vertical spacing between cells
If two values are specified, the first sets the horizontal spacing and the second sets the vertical spacing
caption-side

The caption-side property specifies the placement of a table caption.

caption-side: top;

 

ValueDescription
topPuts the caption above the table. This is default
bottomPuts the caption below the table

Background & Borders

background

The background property is a shorthand property for:

  • background-color

  • background-image

  • background-position

  • background-size

  • background-repeat

  • background-origin

  • background-clip

  • background-attachment

It does not matter if one of the values above are missing, e.g. background:#ff0000 url(smiley.gif); is allowed.

background: lightblue url("img_tree.gif") no-repeat fixed center;

background-color

The background-color property sets the background color of an element.

The background of an element is the total size of the element, including padding and border (but not the margin).

Tip: Use a background color and a text color that makes the text easy to read.

background-color: coral;

 

ValueDescription
colorSpecifies the background color. Look at CSS Color Values for a complete list of possible color values.
transparentSpecifies that the background color should be transparent. This is default
background-image

The background-image property sets one or more background images for an element.

By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

Tip: The background of an element is the total size of the element, including padding and border (but not the margin).

Tip: Always set a background-color to be used if the image is unavailable.

background-image: url("paper.gif");

 

ValueDescription
url('URL')The URL to the image. To specify more than one image, separate the URLs with a comma
noneNo background image will be displayed. This is default
conic-gradient()Sets a conic gradient as the background image. Define at least two colors
linear-gradient()Sets a linear gradient as the background image. Define at least two colors (top to bottom)
radial-gradient()Sets a radial gradient as the background image. Define at least two colors (center to edges)
repeating-conic-gradient()Repeats a conic gradient
repeating-linear-gradient()Repeats a linear gradient
repeating-radial-gradient()Repeats a radial gradient
background-position

The background-position property sets the starting position of a background image.

Tip: By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

background-position: center;

 

ValueDescription
left topIf you only specify one keyword, the other value will be "center"
left centerIf you only specify one keyword, the other value will be "center"
left bottomIf you only specify one keyword, the other value will be "center"
right topIf you only specify one keyword, the other value will be "center"
right centerIf you only specify one keyword, the other value will be "center"
right bottomIf you only specify one keyword, the other value will be "center"
center topIf you only specify one keyword, the other value will be "center"
center centerIf you only specify one keyword, the other value will be "center"
center bottomIf you only specify one keyword, the other value will be "center"
x% y%The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0%
xpos yposThe first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions
background-size

The background-size property specifies the size of the background images.

There are four different syntaxes you can use with this property:

  • Keyword syntax ("auto", "cover" and "contain"),

  • One-value syntax (sets the width of the image (height becomes "auto"),

  • The two-value syntax (first value: width of the image, second value: height),

  • The multiple background syntax (separated with comma).

background-size: 300px 100px;

 

ValueDescription
autoDefault value. The background image is displayed in its original size
lengthSets the width and height of the background image. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto". Read about length units
percentageSets the width and height of the background image in percent of the parent element. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
coverResize the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges
containResize the background image to make sure the image is fully visible
background-repeat

The background-repeat property sets if/how a background image will be repeated.

By default, a background-image is repeated both vertically and horizontally.

background-repeat: repeat-y;

 

ValueDescription
repeatThe background image is repeated both vertically and horizontally. The last image will be clipped if it does not fit. This is default
repeat-xThe background image is repeated only horizontally
repeat-yThe background image is repeated only vertically
no-repeatThe background-image is not repeated. The image will only be shown once
spaceThe background-image is repeated as much as possible without clipping. The first and last image is pinned to either side of the element, and whitespace is distributed evenly between the images
roundThe background-image is repeated and squished or stretched to fill the space (no gaps)
background-origin

The background-origin property specifies the origin position (the background positioning area) of a background image.

Note: This property has no effect if background-attachment is "fixed".

background-origin: content-box;

 

ValueDescription
padding-boxDefault value. The background image starts from the upper left corner of the padding edge
border-boxThe background image starts from the upper left corner of the border
content-boxThe background image starts from the upper left corner of the content
background-clip

The background-clip property defines how far the background (color or image) should extend within an element.

background-clip: padding-box;

 

ValueDescription
border-boxDefault value. The background extends behind the border
padding-boxThe background extends to the inside edge of the border
content-boxThe background extends to the edge of the content box
background-attachment

The background-attachment property sets whether a background image scrolls with the rest of the page, or is fixed.

background-attachment: fixed;

 

ValueDescription
scrollThe background image will scroll with the page. This is default
fixedThe background image will not scroll with the page
localThe background image will scroll with the element's contents
background-blend-mode

The background-blend-mode property defines the blending mode of each background layer (color and/or image).

background-blend-mode: lighten;

 

ValueDescription
normalThis is default. Sets the blending mode to normal
multiplySets the blending mode to multiply
screenSets the blending mode to screen
overlaySets the blending mode to overlay
darkenSets the blending mode to darken
lightenSets the blending mode to lighten
color-dodgeSets the blending mode to color-dodge
saturationSets the blending mode to saturation
colorSets the blending mode to color
luminositySets the blending mode to luminosity
border

The border property is a shorthand property for:

  • border-width

  • border-style (required)

  • border-color

If border-color is omitted, the color applied will be the color of the text.

border: 4px dotted blue;

 

PropertyDescription
border-topA shorthand property for border-top-width, border-top-style and border-top-color
border-rightA shorthand property for all the border-right-* properties
border-bottomA shorthand property for border-bottom-width, border-bottom-style and border-bottom-color
border-leftA shorthand property for all the border-left-* properties
border-width

The border-width property sets the width of an element's four borders. This property can have from one to four values.

border-width: thin medium thick 10px;

  • top border is thin

  • right border is medium

  • bottom border is thick

  • left border is 10p

border-width: thin medium thick;

  • top border is thin

  • right and left borders are medium

  • bottom border is thick

border-width: thin medium;

  • top and bottom borders are thin

  • right and left borders are medium

border-width: thin;

  • all four borders are thin

Note: Always declare the border-style property before the border-width property. An element must have borders before you can set the width.

ValueDescription
mediumSpecifies a medium border. This is default
thinSpecifies a thin border
thickSpecifies a thick border
lengthAllows you to define the thickness of the border.
border-style

The border-style property sets the style of an element's four borders. This property can have from one to four values.

border-style: dotted solid double dashed;

  • top border is dotted

  • right border is solid

  • bottom border is double

  • left border is dashed

border-style: dotted solid double;

  • top border is dotted

  • right and left borders are solid

  • bottom border is double

border-style: dotted solid;

  • top and bottom borders are dotted

  • right and left borders are solid

border-style: dotted;

  • all four borders are dotted

ValueDescription
noneDefault value. Specifies no border
hiddenThe same as "none", except in border conflict resolution for table elements
dottedSpecifies a dotted border
dashedSpecifies a dashed border
solidSpecifies a solid border
doubleSpecifies a double border
grooveSpecifies a 3D grooved border. The effect depends on the border-color value
ridgeSpecifies a 3D ridged border. The effect depends on the border-color value
insetSpecifies a 3D inset border. The effect depends on the border-color value
outsetSpecifies a 3D outset border. The effect depends on the border-color value
border-color

The border-color property sets the color of an element's four borders. This property can have from one to four values.

border-color: red green blue pink;

  • top border is red

  • right border is green

  • bottom border is blue

  • left border is pink

border-color: red green blue;

  • top border is red

  • right and left borders are green

  • bottom border is blue

border-color: red green;

  • top and bottom borders are red

  • right and left borders are green

border-color: red;

  • all four borders are red

Note: Always declare the border-style property before the border-color property. An element must have borders before you can change the color.

ValueDescription
colorSpecifies the border color. Look at CSS Color Values for a complete list of possible color values. Default color is the current color of the element
transparentSpecifies that the border color should be transparent
border-radius

The border-radius property defines the radius of the element's corners.

Tip: This property allows you to add rounded corners to elements!

border-radius: 15px 50px 30px 5px;

  • first value applies to top-left corner

  • second value applies to top-right corner

  • third value applies to bottom-right corner

  • fourth value applies to bottom-left corner

border-radius: 15px 50px 30px;

  • first value applies to top-left corner

  • second value applies to top-right and bottom-left corners

  • third value applies to bottom-right corner

border-radius: 15px 50px;

  • first value applies to top-left and bottom-right corners

  • second value applies to top-right and bottom-left corners

border-radius: 15px;

  • value applies to all four corners, which are rounded equally

ValueDescription
lengthDefines the shape of the corners. Default value is 0. Read about length units
%Defines the shape of the corners in %

 

PropertyDescription
border-top-left-radiusDefines the radius of the border of the top-left corner
border-top-right-radiusDefines the radius of the border of the top-right corner
border-bottom-right-radiusDefines the radius of the border of the bottom-right corner
border-bottom-left-radiusDefines the radius of the border of the bottom-left corner
border-image

The border-image property allows you to specify an image to be used as the border around an element.

The border-image property is a shorthand property for:

  • border-image-source

  • border-image-slice

  • border-image-width

  • border-image-outset

  • border-image-repeat

Omitted values are set to their default values.

border-image: url(border.png) 30 round;

border-image-source

The border-image-source property specifies the path to the image to be used as a border (instead of the normal border around an element).

Tip: If the value is "none", or if the image cannot be displayed, the border styles will be used.

border-image-source: url(border.png);

 

ValueDescription
noneNo image will be used
imageThe path to the image to be used as a border
border-image-slice

The border-image-slice property specifies how to slice the image specified by border-image-source. The image is always sliced into nine sections: four corners, four edges and the middle.

The "middle" part is treated as fully transparent, unless the fill keyword is set.

border-image-slice: 30%;

 

ValueDescription
numberThe number(s) represent pixels for raster images or coordinates for vector images
%Percentages are relative to the height or width of the image
fillCauses the middle part of the image to be displayed
border-image-width

The border-image-width property specifies the width of the border image.

border-image-width: 10px;

 

ValueDescription
lengthA length unit (px) specifying the size of the border-width
numberDefault value 1. Represents multiples of the corresponding border-width
%Refers to the size of the border image area: the width of the area for horizontal offsets, the height for vertical offsets
autoIf specified, the width is the intrinsic width or height of the corresponding image slice
border-image-outset

The border-image-outset property specifies the amount by which the border image area extends beyond the border box.

border-image-outset: 10px;

 

ValueDescription
lengthA length unit specifying how far from the edges the border-image will appear. Default value is 0
numberRepresent multiples of the corresponding border-width
border-image-repeat

The border-image-repeat property specifies whether the border image should be repeated, rounded, spaced or stretched.

border-image-repeat: repeat;

 

ValueDescription
stretchDefault value. The image is stretched to fill the area
repeatThe image is tiled (repeated) to fill the area
roundThe image is tiled (repeated) to fill the area. If it does not fill the area with a whole number of tiles, the image is rescaled so it fits
spaceThe image is tiled (repeated) to fill the area. If it does not fill the area with a whole number of tiles, the extra space is distributed around the tiles
box-decoration-break

Sets the behavior of the background and border of an element at page-break, or, for in-line elements, at line-break.

-webkit-box-decoration-break: slice;

 

ValueDescription
sliceDefault. Box decorations are applied to the element as a whole and break at the edges of the element fragments
cloneBox decorations apply to each fragment of the element as if the fragments were individual elements. Borders wrap the four edges of each fragment of the element, and backgrounds are redrawn in full for each fragment
box-shadow

The box-shadow property attaches one or more shadows to an element.

box-shadow: 5px 10px #888888;

 

ValueDescription
noneDefault value. No shadow is displayed
h-offsetRequired. The horizontal offset of the shadow. A positive value puts the shadow on the right side of the box, a negative value puts the shadow on the left side of the box
v-offsetRequired. The vertical offset of the shadow. A positive value puts the shadow below the box, a negative value puts the shadow above the box
blurOptional. The blur radius. The higher the number, the more blurred the shadow will be
spreadOptional. The spread radius. A positive value increases the size of the shadow, a negative value decreases the size of the shadow
colorOptional. The color of the shadow. The default value is the text color. Look at CSS Color Values for a complete list of possible color values.
Note: In Safari (on PC) the color parameter is required. If you do not specify the color, the shadow is not displayed at all.
insetOptional. Changes the shadow from an outer shadow (outset) to an inner shadow

Container Style

visibility

The visibility property specifies whether or not an element is visible.

visibility: hidden;

 

ValueDescription
visibleDefault value. The element is visible
hiddenThe element is hidden (but still takes up space)
collapseOnly for table rows (<tr>), row groups (<tbody>), columns (<col>), column groups (<colgroup>). This value removes a row or column, but it does not affect the table layout. The space taken up by the row or column will be available for other content. If collapse is used on other elements, it renders as "hidden"
opacity

The opacity property sets the opacity level for an element.

The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.

opacity: 0.5;

 

ValueDescription
numberSpecifies the opacity. From 0.0 (fully transparent) to 1.0 (fully opaque)
cursor

The cursor property specifies the mouse cursor to be displayed when pointing over an element.

cursor: zoom-in;

 

ValueDescription
aliasThe cursor indicates an alias of something is to be created
all-scrollThe cursor indicates that something can be scrolled in any direction
autoDefault. The browser sets a cursor
cellThe cursor indicates that a cell (or set of cells) may be selected
context-menuThe cursor indicates that a context-menu is available
col-resizeThe cursor indicates that the column can be resized horizontally
copyThe cursor indicates something is to be copied
crosshairThe cursor render as a crosshair
defaultThe default cursor
e-resizeThe cursor indicates that an edge of a box is to be moved right (east)
ew-resizeIndicates a bidirectional resize cursor
grabThe cursor indicates that something can be grabbed
grabbingThe cursor indicates that something can be grabbed
helpThe cursor indicates that help is available
moveThe cursor indicates something is to be moved
n-resizeThe cursor indicates that an edge of a box is to be moved up (north)
ne-resizeThe cursor indicates that an edge of a box is to be moved up and right (north/east)
nesw-resizeIndicates a bidirectional resize cursor
ns-resizeIndicates a bidirectional resize cursor
nw-resizeThe cursor indicates that an edge of a box is to be moved up and left (north/west)
nwse-resizeIndicates a bidirectional resize cursor
no-dropThe cursor indicates that the dragged item cannot be dropped here
noneNo cursor is rendered for the element
not-allowedThe cursor indicates that the requested action will not be executed
pointerThe cursor is a pointer and indicates a link
progressThe cursor indicates that the program is busy (in progress)
row-resizeThe cursor indicates that the row can be resized vertically
s-resizeThe cursor indicates that an edge of a box is to be moved down (south)
se-resizeThe cursor indicates that an edge of a box is to be moved down and right (south/east)
sw-resizeThe cursor indicates that an edge of a box is to be moved down and left (south/west)
textThe cursor indicates text that may be selected
URLA comma separated list of URLs to custom cursors. Note: Always specify a generic cursor at the end of the list, in case none of the URL-defined cursors can be used
vertical-textThe cursor indicates vertical-text that may be selected
w-resizeThe cursor indicates that an edge of a box is to be moved left (west)
waitThe cursor indicates that the program is busy
zoom-inThe cursor indicates that something can be zoomed in
zoom-outThe cursor indicates that something can be zoomed out
caret-color

The caret-color property specifies the color of the cursor (caret) in inputs, textareas, or any element that is editable.

caret-color: red;

 

ValueDescription
autoDefault. Browsers uses the currentColor for the caret
colorSpecifies a color to use for the caret. All legal color values can be used (rgb, hex, named-color, etc). For more information on legal values
pointer-events

The pointer-events property defines whether or not an element reacts to pointer events.

pointer-events: auto;

 

ValueDescription
autoThe element reacts to pointer events, like :hover and click. This is default
noneThe element does not react to pointer events
initialSets this property to its default value.
inheritInherits this property from its parent element.
scroll-behavior

The scroll-behavior property specifies whether to smoothly animate the scroll position, instead of a straight jump, when the user clicks on a link within a scrollable box.

scroll-behavior: smooth;

 

ValueDescription
autoAllows a straight jump "scroll effect" between elements within the scrolling box. This is default
smoothAllows a smooth animated "scroll effect" between elements within the scrolling box.
filter

The filter property defines visual effects (like blur and saturation) to an element (often <img>).

scroll-behavior: smooth;

 

ValueDescription
noneDefault value. Specifies no effects
blur(px)Applies a blur effect to the image. A larger value will create more blur.

If no value is specified, 0 is used.
brightness(%)Adjusts the brightness of the image.

0% will make the image completely black.
100% (1) is default and represents the original image.

Values over 100% will provide brighter results.
contrast(%)Adjusts the contrast of the image.

0% will make the image completely black.
100% (1) is default, and represents the original image.

Values over 100% will provide results with more contrast.
drop-shadow(h-shadow v-shadow blur spread color)Applies a drop shadow effect to the image.

Possible values:
h-shadow - Required. Specifies a pixel value for the horizontal shadow. Negative values place the shadow to the left of the image.

v-shadow - Required. Specifies a pixel value for the vertical shadow. Negative values place the shadow above the image.

blur - Optional. This is the third value, and must be in pixels. Adds a blur effect to the shadow. A larger value will create more blur (the shadow becomes bigger and lighter). Negative values are not allowed. If no value is specified, 0 is used (the shadow's edge is sharp).

spread - Optional. This is the fourth value, and must be in pixels. Positive values will cause the shadow to expand and grow bigger, and negative values will cause the shadow to shrink. If not specified, it will be 0 (the shadow will be the same size as the element).
Note: Chrome, Safari and Opera, and maybe other browsers, do not support this 4th length; it will not render if added.

color - Optional. Adds a color to the shadow. If not specified, the color depends on the browser (often black). An example of creating a red shadow, which is 8px big both horizontally and vertically, with a blur effect of 10px:

filter: drop-shadow(8px 8px 10px red);
Tip: This filter is similar to the box-shadow property.
grayscale(%)Converts the image to grayscale.

0% (0) is default and represents the original image.
100% will make the image completely gray (used for black and white images).

Note: Negative values are not allowed.
hue-rotate(deg)Applies a hue rotation on the image. The value defines the number of degrees around the color circle the image samples will be adjusted. 0deg is default, and represents the original image.

Note: Maximum value is 360deg.
invert(%)Inverts the samples in the image.

0% (0) is default and represents the original image.
100% will make the image completely inverted.

Note: Negative values are not allowed.
opacity(%) Sets the opacity level for the image. The opacity-level describes the transparency-level, where:

0% is completely transparent.
100% (1) is default and represents the original image (no transparency).

Note: Negative values are not allowed.
Tip: This filter is similar to the opacity property.
saturate(%)Saturates the image.

0% (0) will make the image completely un-saturated.
100% is default and represents the original image.

Values over 100% provides super-saturated results.

Note: Negative values are not allowed.
sepia(%)Converts the image to sepia.

0% (0) is default and represents the original image.
100% will make the image completely sepia.

Note: Negative values are not allowed.
url()The url() function takes the location of an XML file that specifies an SVG filter, and may include an anchor to a specific filter element. Example:

filter: url(svg-url#element-id)
mix-blend-mode

The mix-blend-mode property specifies how an element's content should blend with its direct parent background.

mix-blend-mode: darken;

 

ValueDescription
normalThis is default. Sets the blending mode to normal
multiplySets the blending mode to multiply
screenSets the blending mode to screen
overlaySets the blending mode to overlay
darkenSets the blending mode to darken
lightenSets the blending mode to lighten
color-dodgeSets the blending mode to color-dodge
color-burnSets the blending mode to color-burn
differenceSets the blending mode to difference
exclusionSets the blending mode to exclusion
hueSets the blending mode to hue
saturationSets the blending mode to saturation
colorSets the blending mode to color
luminositySets the blending mode to luminosity
white-space

The white-space property specifies how white-space inside an element is handled.

white-space: pre;

 

ValueDescription
normalSequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default
nowrapSequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered
preWhitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML
pre-lineSequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks
pre-wrapWhitespace is preserved by the browser. Text will wrap when necessary, and on line breaks
backface-visibility

The backface-visibility property defines whether or not the back face of an element should be visible when facing the user.

The back face of an element is a mirror image of the front face being displayed.

This property is useful when an element is rotated. It lets you choose if the user should see the back face or not.

-webkit-backface-visibility: visible;

 

ValueDescription
visibleDefault value. The backside is visible
hiddenThe backside is not visible
isolation

The isolation property defines whether an element must create a new stacking content.

Note: The isolation property is helpful when used with background-blend-mode or mix-blend-mode.

isolation: isolate;

 

ValueDescription
autoDefault. A new stacking context is created only if one of the properties applied to the element requires it
isolateA new stacking context must be created

Masks

mask

Hides parts of an element by masking or clipping an image at specific places

mask-clip

Specifies the mask area

mask-composite

Represents a compositing operation used on the current mask layer with the mask layers below it

mask-image

The mask-image property specifies an image to be used as a mask layer for an element.

Tip: Linear and radial gradients in CSS can also be used as the mask image.

mask-image: url(w3logo.png);

 

ValueDescription
noneThis is default
imageAn image to use as the mask layer
urlAn url reference to an image or an SVG <mask> element
mask-mode

The mask-mode property specifies whether the mask layer image should be treated as a luminance mask or as an alpha mask.

mask-mode: luminance;

 

ValueDescription
match-sourceIf the mask-image property is an image (an image URL or a gradient), set mask-mode to alpha. If the mask-image property is an SVG <mask> element, use the <mask> element's mask-type property. This is default.
luminanceUse the luminance values of the mask image as the mask values
alphaUse the alpha values of the mask image as the mask values
mask-origin

The mask-origin property specifies the origin position (the mask position area) of a mask layer image.

mask-origin: content-box;

 

ValueDescription
border-boxThe position is relative to the border box. This is default
content-boxThe position is relative to the content box
padding-boxThe position is relative to the padding box
margin-boxThe position is relative to the margin box
fill-boxThe position is relative to the object bounding box
stroke-boxThe position is relative to the stroke bounding box
view-boxUse the nearest SVG viewport as reference box
mask-position

The mask-position property sets the starting position of a mask image (relative to the mask position area).

Tip: By default, a mask image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

mask-position: center;

 

ValueDescription
left topIf you only specify one keyword, the other value will be "center"
left centerIf you only specify one keyword, the other value will be "center"
left bottomIf you only specify one keyword, the other value will be "center"
right topIf you only specify one keyword, the other value will be "center"
right centerIf you only specify one keyword, the other value will be "center"
right bottomIf you only specify one keyword, the other value will be "center"
center topIf you only specify one keyword, the other value will be "center"
center centerIf you only specify one keyword, the other value will be "center"
center bottomIf you only specify one keyword, the other value will be "center"
x% y%The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0%
xpos yposThe first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions
mask-repeat

The mask-repeat property sets if/how a mask image will be repeated.

By default, a mask image is repeated both vertically and horizontally.

mask-repeat: repeat;

 

ValueDescription
repeatThe mask image is repeated both vertically and horizontally. The last image will be clipped if it does not fit. This is default
repeat-xThe mask image is repeated only horizontally
repeat-yThe mask image is repeated only vertically
spaceThe mask image is repeated as much as possible without clipping. The first and last image is pinned to either side of the element, and whitespace is distributed evenly between the images
roundThe mask image is repeated and squished or stretched to fill the space (no gaps)
no-repeatThe mask image is not repeated. The image will only be shown once
mask-size

The mask-size property specifies the size of the mask layer image.

mask-size: 70%;

 

ValueDescription
autoThis is default
sizeSpecifies the size of the mask image in px, em, etc, or in %
containScales the mask image in a way that both its width and its height fit inside the container
coverScales the mask image in a way that both its width and its height cover the container
mask-type

Specifies whether an SVG <mask> element is treated as a luminance mask or as an alpha mask

Font

color

The color property specifies the color of text.

Tip:Use a background color combined with a text color that makes the text easy to read.

color: red;

color: #00ff00;

color: rgb(0,0,255);

 

ValueDescription
colorSpecifies the text color
font

The font property is a shorthand property for:

  • font-style

  • font-variant

  • font-weight

  • font-size/line-height

  • font-family

The font-size and font-family values are required. If one of the other values is missing, their default value are used.

Note: The line-height property sets the space between lines.

font: italic small-caps bold 12px/30px Georgia, serif;

font-style

The font-style property specifies the font style for a text.

font-style: italic;

 

ValueDescription
normalThe browser displays a normal font style. This is default
italicThe browser displays an italic font style
obliqueThe browser displays an oblique font style
font-variant

In a small-caps font, all lowercase letters are converted to uppercase letters. However, the converted uppercase letters appears in a smaller font size than the original uppercase letters in the text.

The font-variant property specifies whether or not a text should be displayed in a small-caps font.

font-variant: small-caps;

 

ValueDescription
normalThe browser displays a normal font. This is default
small-capsThe browser displays a small-caps font
font-weight

The font-weight property sets how thick or thin characters in text should be displayed.

font-weight: bold;

font-weight: 900;

 

ValueDescription
normalDefines normal characters. This is default
boldDefines thick characters
bolderDefines thicker characters
lighterDefines lighter characters
100
200
300
400
500
600
700
800
900
Defines from thin to thick characters. 400 is the same as normal, and 700 is the same as bold
font-size

The font-size property sets the size of a font.

font-size: 15px;

font-size: large;

font-size: 150%;

 

ValueDescription
mediumSets the font-size to a medium size. This is default
xx-smallSets the font-size to an xx-small size
x-smallSets the font-size to an extra small size
smallSets the font-size to a small size
largeSets the font-size to a large size
x-largeSets the font-size to an extra large size
xx-largeSets the font-size to an xx-large size
smallerSets the font-size to a smaller size than the parent element
largerSets the font-size to a larger size than the parent element
lengthSets the font-size to a fixed size in px, cm, etc. Read about length units
%Sets the font-size to a percent of the parent element's font size
font-family

The font-family property specifies the font for an element.

The font-family property can hold several font names as a "fallback" system. If the browser does not support the first font, it tries the next font.

There are two types of font family names:

  • family-name - The name of a font-family, like "times", "courier", "arial", etc.

  • generic-family - The name of a generic-family, like "serif", "sans-serif", "cursive", "fantasy", "monospace".

Start with the font you want, and always end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available.

Note: Separate each value with a comma.

Note: If a font name contains white-space, it must be quoted. Single quotes must be used when using the "style" attribute in HTML.

font-family: "Times New Roman", Times, serif;

font-family: Arial, Helvetica, sans-serif;

 

ValueDescription
family-name / generic-familyA prioritized list of font family names and/or generic family names
font-size-adjust

The font-size-adjust property gives you better control of the font size when the first selected font is not available.

When a font is not available, the browser uses the second specified font. This could result in a big change for the font size. To prevent this, use the font-size-adjust property.

All fonts have an "aspect value" which is the size-difference between the lowercase letter "x" and the uppercase letter "X".

When the browser knows the "aspect value" for the first selected font, the browser can figure out what font-size to use when displaying text with the second choice font.

font-size-adjust: 0.58;

 

ValueDescription
numberDefines the aspect value to use
noneDefault value. No font size adjustment
font-stretch

The font-stretch property allows you to make text narrower (condensed) or wider (expanded).

Note: Some fonts provide additional faces; condensed faces and expanded faces. For these fonts, you can use the font-stretch property to select a normal, condensed, or expanded font face.

Note: This property has no effect if the selected font does not offer condensed or expanded faces!

font-stretch: expanded;

 

ValueDescription
ultra-condensedMakes the text as narrow as it gets
extra-condensedMakes the text narrower than condensed, but not as narrow as ultra-condensed
condensedMakes the text narrower than semi-condensed, but not as narrow as extra-condensed
semi-condensedMakes the text narrower than normal, but not as narrow as condensed
normalDefault value. No font stretching
semi-expandedMakes the text wider than normal, but not as wide as expanded
expandedMakes the text wider than semi-expanded, but not as wide as extra-expanded
extra-expandedMakes the text wider than expanded, but not as wide as ultra-expanded
ultra-expandedMakes the text as wide as it gets
font-variant-caps

The font-variant-caps property controls the usage of alternate glyphs for capital letters.

font-variant-caps: unicase;

 

ValueDescription
normalDeactivates the use of alternate glyphs
small-capsDisplays small capitals
all-small-capsDisplays small capitals for both upper and lowercase letters
petite-capsDisplays petite capitals
all-petite-capsDisplays petite capitals for both upper and lowercase letters
unicaseDisplays a mix of small capitals for uppercase letters with normal lowercase letters
titling-capsDisplays titling capitals
unset
font-feature-settings

The font-feature-settings property allows control over advanced typographic features in OpenType fonts.

font-feature-settings: "frac";

 

ValueDescription
normalDefault. Use the default settings to lay out text
feature-valueFormat: string [1|0|on|off] Always a string of 4 ASCII characters.

Formatting (Positioning)

hanging-punctuation

The hanging-punctuation property specifies whether a punctuation mark may be placed outside the line box at the start or at the end of a full line of text.

hanging-punctuation: first;

 

ValueDescription
noneNo punctuation mark may be placed outside the line box at the start or at the end of a full line of text
firstPunctuation may hang outside the start edge of the first line
lastPunctuation may hang outside the end edge of the last line
allow-endPunctuation may hang outside the end edge of all lines if the punctuation does not otherwise fit prior to justification
force-endPunctuation may hang outside the end edge of all lines. If justification is enabled on this line, then it will force the punctuation to hang
line-height

The line-height property specifies the height of a line.

Note: Negative values are not allowed.

line-height: normal;

line-height: 1.6; //Recommended

line-height: 80%;

 

ValueDescription
normalA normal line height. This is default
numberA number that will be multiplied with the current font-size to set the line height
lengthA fixed line height in px, pt, cm, etc.
%A line height in percent of the current font size
text-align

The text-align property specifies the horizontal alignment of text in an element.

text-align: justify;

 

ValueDescription
leftAligns the text to the left
rightAligns the text to the right
centerCenters the text
justifyStretches the lines so that each line has equal width (like in newspapers and magazines)
text-align-last

The text-align-last property specifies how to align the last line of a text.

Notice that the text-align-last property sets the alignment for all last lines within the selected element. So, if you have a <div> with three paragraphs in it, text-align-last will apply to the last line of EACH of the paragraphs. To use text-align-last on only the last paragraph in the container, you can use :last child, see example below.

Note: In Edge prior 79, the text-align-last property only works on text that has "text-align: justify".

text-align-last: center;

 

ValueDescription
autoDefault value. The last line is justified and aligned left
leftThe last line is aligned to the left
rightThe last line is aligned to the right
centerThe last line is center-aligned
justifyThe last line is justified as the rest of the lines
startThe last line is aligned at the beginning of the line (left if the text-direction is left-to-right, and right is the text-direction is right-to-left)
endThe last line is aligned at the end of the line (right if the text-direction is left-to-right, and left is the text-direction is right-to-left)
text-justify

The text-justify property specifies the justification method of text when text-align is set to "justify".

text-justify: inter-word;

 

ValueDescription
autoThe browser determines the justification algorithm
inter-wordIncreases/Decreases the space between words
inter-characterIncreases/Decreases the space between characters
noneDisables justification methods

Formatting (Spacing)

font-kerning

The font-kerning property controls the usage of the kerning information stored in a font.

Tip:Kerning defines how letters are spaced.

Note: For fonts that do not include kerning data, this property will have no visible effect.

font-kerning: normal;

 

ValueDescription
autoDefault. The browser determines whether font kerning should be applied or not
normalSpecifies that font kerning is applied
noneSpecifies that font kerning is not applied
letter-spacing

The letter-spacing property increases or decreases the space between characters in a text.

letter-spacing: -1px;

 

ValueDescription
normalDefines normal space between characters. This is default
lengthDefines a length that is used as the space between characters (negative values are also allowed). Read about length units
tab-size

The tab-size property specifies the width of a tab character.

In HTML, the tab character is usually displayed as a single space-character, except for some elements, like <textarea> and <pre>, and the result of the tab-size property will only be visible for those elements.

tab-size: 16;

 

ValueDescription
numberThe number of space-characters to be displayed for each tab-character. Default value is 8
lengthThe length of a tab-character. This property value is not supported in any of the major browsers
text-indent

The text-indent property specifies the indentation of the first line in a text-block.

Note: Negative values are allowed. The first line will be indented to the left if the value is negative.

text-indent: 50px;

text-indent: -2em;

text-indent: 30%;

 

ValueDescription
lengthDefines a fixed indentation in px, pt, cm, em, etc. Default value is 0. Read about length units
%Defines the indentation in % of the width of the parent element
word-spacing

The word-spacing property increases or decreases the white space between words.

Note: Negative values are allowed.

word-spacing: 30px;

 

ValueDescription
normalDefines normal space between words (0.25em) . This is default
lengthDefines an additional space between words (in px, pt, cm, em, etc). Negative values are allowed. Read about length units

Lists, Outlines & Decorations

list-style

The list-style property is a shorthand for the following properties:

  • list-style-type

  • list-style-position

  • list-style-image

If one of the values are missing, the default value for that property will be used.

list-style: square inside url("sqpurple.gif");

list-style-type

The list-style-type specifies the type of list-item marker in a list.

list-style-type: square;

 

ValueDescription
discDefault value. The marker is a filled circle
armenianThe marker is traditional Armenian numbering
circleThe marker is a circle
cjk-ideographicThe marker is plain ideographic numbers
decimalThe marker is a number
decimal-leading-zeroThe marker is a number with leading zeros (01, 02, 03, etc.)
georgianThe marker is traditional Georgian numbering
hebrewThe marker is traditional Hebrew numbering
hiraganaThe marker is traditional Hiragana numbering
hiragana-irohaThe marker is traditional Hiragana iroha numbering
katakanaThe marker is traditional Katakana numbering
katakana-irohaThe marker is traditional Katakana iroha numbering
lower-alphaThe marker is lower-alpha (a, b, c, d, e, etc.)
lower-greekThe marker is lower-greek
lower-latinThe marker is lower-latin (a, b, c, d, e, etc.)
lower-romanThe marker is lower-roman (i, ii, iii, iv, v, etc.)
noneNo marker is shown
squareThe marker is a square
upper-alphaThe marker is upper-alpha (A, B, C, D, E, etc.)
upper-greekThe marker is upper-greek
upper-latinThe marker is upper-latin (A, B, C, D, E, etc.)
upper-romanThe marker is upper-roman (I, II, III, IV, V, etc.)
list-style-position

The list-style-position property specifies the position of the list-item markers (bullet points).

list-style-position: outside; means that the bullet points will be outside the list item. The start of each line of a list item will be aligned vertically:

list-style-position: inside; means that the bullet points will be inside the list item. As it is part of the list item, it will be part of the text and push the text at the start:

list-style-position: inside;

 

ValueDescription
insideThe bullet points will be inside the list item
outsideThe bullet points will be outside the list item. This is default
list-style-image

The list-style-image property replaces the list-item marker with an image.

Note: Always specify the list-style-type property in addition. This property is used if the image for some reason is unavailable.

list-style-image: url('sqpurple.gif');

 

ValueDescription
noneNo image will be displayed. Instead, the list-style-type property will define what type of list marker will be rendered. This is default
urlThe path to the image to be used as a list-item marker
outline

An outline is a line that is drawn around elements, outside the borders, to make the element "stand out".

The outline property is a shorthand property for:

  • outline-width

  • outline-style (required)

  • outline-color

If outline-color is omitted, the color applied will be the color of the text.

Note: Outlines differ from borders! Unlike border, the outline is drawn outside the element's border, and may overlap other content. Also, the outline is NOT a part of the element's dimensions; the element's total width and height is not affected by the width of the outline.

outline: 2px dashed blue;

outline-width

The outline-width specifies the width of an outline.

Note: Note: Always declare the outline-style property before the outline-width property. An element must have an outline before you change the width of it.

outline-width: thick;

 

ValueDescription
mediumSpecifies a medium outline. This is default
thinSpecifies a thin outline
thickSpecifies a thick outline
lengthAllows you to define the thickness of the outline. Read about length units
outline-style

An outline is a line that is drawn around elements, outside the borders, to make the element "stand out".

The outline-style property specifies the style of an outline.

outline-style: dotted;

 

ValueDescription
noneSpecifies no outline. This is default
hiddenSpecifies a hidden outline
dottedSpecifies a dotted outline
dashedSpecifies a dashed outline
solidSpecifies a solid outline
doubleSpecifies a double outliner
grooveSpecifies a 3D grooved outline. The effect depends on the outline-color value
ridgeSpecifies a 3D ridged outline. The effect depends on the outline-color value
insetSpecifies a 3D inset outline. The effect depends on the outline-color value
outsetSpecifies a 3D outset outline. The effect depends on the outline-color value
outline-color

The outline-color property specifies the color of an outline.

Note: Always declare the outline-style property before the outline-color property. An element must have an outline before you change the color of it.

outline-color: coral;

 

ValueDescription
invertPerforms a color inversion. This ensures that the outline is visible, regardless of color background. Note: Browsers are not required to support this value.
colorSpecifies the color of the outline. Look at CSS Color Values for a complete list of possible color values.
outline-offset

The outline-offset property adds space between the outline and the edge or border of an element.

The space between an element and its outline is transparent.

Outlines differ from borders in three ways:

  • An outline is a line drawn around elements, outside the border edge

  • An outline does not take up space

  • An outline may be non-rectangular

outline-offset: 15px;

 

ValueDescription
lengthThe distance the outline is outset from the border edge. Default value is 0
text-decoration

The text-decoration property specifies the decoration added to text, and is a shorthand property for:

  • text-decoration-line (required)

  • text-decoration-color

  • text-decoration-style

  • text-decoration-thickness

text-decoration: underline overline;

text-decoration-line

The text-decoration-line property sets the kind of text decoration to use (like underline, overline, line-through).

Note: You can also combine more than one value, like underline and overline to display lines both under and over the text.

text-decoration-line: line-through;

 

ValueDescription
noneDefault value. Specifies no line for the text-decoration
underlineSpecifies that a line will be displayed under the text
overlineSpecifies that a line will be displayed over the text
line-throughSpecifies that a line will be displayed through the text
text-decoration-color

The text-decoration-color property specifies the color of the text-decoration (underlines, overlines, linethroughs).

text-decoration-color: red;

 

ValueDescription
colorSpecifies the color of the text-decoration
text-decoration-style

The text-decoration-style property sets the style of the text decoration (like solid, wavy, dotted, dashed, double).

text-decoration-style: wavy;

 

ValueDescription
solidDefault value. The line will display as a single line
doubleThe line will display as a double line
dottedThe line will display as a dotted line
dashedThe line will display as a dashed line
wavyThe line will display as a wavy line
text-decoration-thickness

The text-decoration-thickness property specifies the thickness of the decoration line.

text-decoration-thickness: 50%;

 

ValueDescription
autoThe browser chooses the thickness of the decoration line
from-fontIf a font file contains information about a preferred thickness, use that value. If not, behave as auto
length/percentageSpecifies the thickness as a length or %

Breaks & Overflow

overflow

The overflow property specifies what should happen if content overflows an element's box.

This property specifies whether to clip content or to add scrollbars when an element's content is too big to fit in a specified area.

Note: The overflow property only works for block elements with a specified height.

overflow: visible;

 

ValueDescription
visibleThe overflow is not clipped. It renders outside the element's box. This is default
hiddenThe overflow is clipped, and the rest of the content will be invisible. Content can be scrolled programmatically (e.g. by setting scrollLeft or scrollTo())
clipThe overflow is clipped, and the rest of the content will be invisible. Forbids scrolling, including programmatic scrolling.
scrollThe overflow is clipped, but a scroll-bar is added to see the rest of the content
autoIf overflow is clipped, a scroll-bar should be added to see the rest of the content
overflow-x

The overflow-x property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the left and right edges.

Tip: Use the overflow-y property to determine clipping at the top and bottom edges.

overflow-x: visible;

 

ValueDescription
visibleThe content is not clipped, and it may be rendered outside the left and right edges. This is default
hiddenThe content is clipped - and no scrolling mechanism is provided
scrollThe content is clipped and a scrolling mechanism is provided
autoShould cause a scrolling mechanism to be provided for overflowing boxes
overflow-y

The overflow-y property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.

Tio: Use the overflow-x property to determine clipping at the left and right edges.

overflow-y: visible;

 

ValueDescription
visibleThe content is not clipped, and it may be rendered outside the content box. This is default
hiddenThe content is clipped - and no scrolling mechanism is provided
scrollThe content is clipped and a scrolling mechanism is provided
autoShould cause a scrolling mechanism to be provided for overflowing boxes
word-wrap

The word-wrap property allows long words to be able to be broken and wrap onto the next line.

word-wrap: break-word;

 

ValueDescription
normalBreak words only at allowed break points. This is default
break-wordAllows unbreakable words to be broken
word-break

The word-break property specifies how words should break when reaching the end of a line.

word-break: break-all;

 

ValueDescription
normalDefault value. Uses default line break rules
break-allTo prevent overflow, word may be broken at any character
keep-allWord breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as value "normal"
break-wordTo prevent overflow, word may be broken at arbitrary points
text-overflow

The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.

Both of the following properties are required for text-overflow:

  • white-space: nowrap;

  • overflow: hidden;

white-space: nowrap;

overflow: hidden;

text-overflow: ellipsis;

 

ValueDescription
clipDefault value. The text is clipped and not accessible
ellipsisRender an ellipsis ("...") to represent the clipped text
stringRender the given string to represent the clipped text
overflow-wrap

The overflow-wrap property specifies whether or not the browser can break lines with long words, if they overflow the container.

overflow-wrap: break-word;

 

ValueDescription
normalLong words will not break, even if they overflow the container. This is default
anywhereLong words will break if they overflow the container
break-wordLong words will break if they overflow the container
hyphens

The hyphens property defines whether hyphenation is allowed to create more soft wrap opportunities within a line of text.

hyphens: auto;

 

ValueDescription
noneWords are not hyphenated
manualDefault. Words are only hyphenated at &hyphen; or &shy; (if needed)
autoWords are hyphenated where the algorithm is deciding (if needed)

Formatting (Other)

text-transform

The text-transform property controls the capitalization of text.

text-transform: capitalize;

 

ValueDescription
noneNo capitalization. The text renders as it is. This is default
capitalizeTransforms the first character of each word to uppercase
uppercaseTransforms all characters to uppercase
lowercaseTransforms all characters to lowercase
quotes

The quotes property sets the type of quotation marks for quotations.

quotes: "'" "'";

 

ValueDescription
noneSpecifies that the "open-quote" and "close-quote" values of the "content" property will not produce any quotation marks
string string string stringSpecifies which quotation marks to use. The first two values specifies the first level of quotation embedding, the next two values specifies the next level of quote embedding, etc

Quotation Mark Characters

ValueDescription
"double quote
'single quote
single, left angle quote
single, right angle quote
«double, left angle quote
»double, right angle quote
left quote (single high-6)
right quote (single high-9)
left quote (double high-6)
right quote (double high-9)
double quote (double low-9)
text-shadow

The text-shadow property adds shadow to text.

This property accepts a comma-separated list of shadows to be applied to the text.

text-shadow: 2px 2px #ff0000;

 

ValueDescription
h-shadowRequired. The position of the horizontal shadow. Negative values are allowed
v-shadowRequired. The position of the vertical shadow. Negative values are allowed
blur-radiusOptional. The blur radius. Default value is 0
colorOptional. The color of the shadow. Look at CSS Color Values for a complete list of possible color values
noneDefault value. No shadow
direction

The direction property specifies the text direction/writing direction within a block-level element.

Tip: Use this property together with the unicode-bidi property to set or return whether the text should be overridden to support multiple languages in the same document.

direction: rtl;

 

ValueDescription
ltrText direction goes from left-to-right. This is default
rtlText direction goes from right-to-left
writing-mode

The writing-mode property specifies whether lines of text are laid out horizontally or vertically.

writing-mode: vertical-rl;

 

ValueDescription
horizontal-tbLet the content flow horizontally from left to right, vertically from top to bottom
vertical-rlLet the content flow vertically from top to bottom, horizontally from right to left
vertical-lrLet the content flow vertically from top to bottom, horizontally from left to right
user-select

The user-select property specifies whether the text of an element can be selected.

user-select: none;

 

ValueDescription
autoDefault. Text can be selected if the browser allows it
nonePrevent text selection
textThe text can be selected by the user

Animation

@keyframes

The @keyframes rule specifies the animation code.

The animation is created by gradually changing from one set of CSS styles to another.

During the animation, you can change the set of CSS styles many times.

Specify when the style change will happen in percent, or with the keywords "from" and "to", which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the animation is complete.

Tip: For best browser support, you should always define both the 0% and the 100% selectors.

Note: Use the animation properties to control the appearance of the animation, and also to bind the animation to selectors.

Note: The !important rule is ignored in a keyframe (See last example on this page).

@keyframes mymove {

from {top: 0px;}

to {top: 200px;}

}

 

ValueDescription
animationnameRequired. Defines the name of the animation.
keyframes-selectorRequired. Percentage of the animation duration.
Legal values:
0-100%
from (same as 0%)
to (same as 100%)
Note: You can have many keyframes-selectors in one animation.
css-stylesRequired. One or more legal CSS style properties
animation

The animation property is a shorthand property for:

  • animation-name

  • animation-duration

  • animation-timing-function

  • animation-delay

  • animation-iteration-count

  • animation-direction

  • animation-fill-mode

  • animation-play-state

Note: Always specify the animation-duration property, otherwise the duration is 0, and will never be played.

animation: mymove 5s infinite;

animation-name

The animation-name property specifies a name for the @keyframes animation.

animation-name: mymove;

 

ValueDescription
keyframenameSpecifies the name of the keyframe you want to bind to the selector
noneDefault value. Specifies that there will be no animation (can be used to override animations coming from the cascade)
animation-duration

The animation-duration property defines how long an animation should take to complete one cycle.

animation-duration: 3s;

 

ValueDescription
timeSpecifies the length of time an animation should take to complete one cycle. This can be specified in seconds or milliseconds. Default value is 0, which means that no animation will occur
animation-timing-function

The animation-timing-function specifies the speed curve of an animation.

The speed curve defines the TIME an animation uses to change from one set of CSS styles to another.

The speed curve is used to make the changes smoothly.

animation-timing-function: linear;

 

ValueDescription
linearThe animation has the same speed from start to end
easeDefault value. The animation has a slow start, then fast, before it ends slowly
ease-inThe animation has a slow start
ease-outThe animation has a slow end
ease-in-outThe animation has both a slow start and a slow end
step-startEquivalent to steps(1, start)
step-endEquivalent to steps(1, end)
steps(int,start|end)Specifies a stepping function, with two parameters. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, is either the value "start" or "end", and specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value "end"
cubic-bezier(n,n,n,n)Define your own values in the cubic-bezier function
Possible values are numeric values from 0 to 1
animation-delay

The animation-delay property specifies a delay for the start of an animation.

The animation-delay value is defined in seconds (s) or milliseconds (ms).

animation-delay: 2s;

 

ValueDescription
timeOptional. Defines the number of seconds (s) or milliseconds (ms) to wait before the animation will start. Default value is 0. Negative values are allowed. If you use negative values, the animation will start as if it had already been playing for Nseconds/milliseconds.
animation-iteration-count

The animation-iteration-count property specifies the number of times an animation should be played.

animation-iteration-count: 2;

 

ValueDescription
numberA number that defines how many times an animation should be played. Default value is 1
infiniteSpecifies that the animation should be played infinite times (for ever)
animation-direction

The animation-direction property defines whether an animation should be played forwards, backwards or in alternate cycles.

animation-direction: alternate;

 

ValueDescription
normalDefault value. The animation is played as normal (forwards)
reverseThe animation is played in reverse direction (backwards)
alternateThe animation is played forwards first, then backwards
alternate-reverseThe animation is played backwards first, then forwards
animation-fill-mode

The animation-fill-mode property specifies a style for the element when the animation is not playing (before it starts, after it ends, or both).

CSS animations do not affect the element before the first keyframe is played or after the last keyframe is played. The animation-fill-mode property can override this behavior.

animation-fill-mode: forwards;

 

ValueDescription
noneDefault value. Animation will not apply any styles to the element before or after it is executing
forwardsThe element will retain the style values that is set by the last keyframe (depends on animation-direction and animation-iteration-count)
backwardsThe element will get the style values that is set by the first keyframe (depends on animation-direction), and retain this during the animation-delay period
bothThe animation will follow the rules for both forwards and backwards, extending the animation properties in both directions
animation-play-state

The animation-play-state property specifies whether the animation is running or paused.

Note: Use this property in a JavaScript to pause an animation in the middle of a cycle.

animation-play-state: paused;

 

ValueDescription
pausedSpecifies that the animation is paused
runningDefault value. Specifies that the animation is running

Transformation

transform

The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.

transform: rotate(20deg);

transform: skewY(20deg);

transform: scaleY(1.5);

 

ValueDescription
noneDefines that there should be no transformation
matrix(n,n,n,n,n,n)Defines a 2D transformation, using a matrix of six values
matrix3d (n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n)Defines a 3D transformation, using a 4x4 matrix of 16 values
translate(x,y)Defines a 2D translation
translate3d(x,y,z)Defines a 3D translation
translateX(x)Defines a translation, using only the value for the X-axis
translateY(y)Defines a translation, using only the value for the Y-axis
translateZ(z)Defines a 3D translation, using only the value for the Z-axis
scale(x,y)Defines a 2D scale transformation
scale3d(x,y,z)Defines a 3D scale transformation
scaleX(x)Defines a scale transformation by giving a value for the X-axis
scaleY(y)Defines a scale transformation by giving a value for the Y-axis
scaleZ(z)Defines a 3D scale transformation by giving a value for the Z-axis
rotate(angle)Defines a 2D rotation, the angle is specified in the parameter
rotate3d(x,y,z,angle)Defines a 3D rotation
rotateX(angle)Defines a 3D rotation along the X-axis
rotateY(angle)Defines a 3D rotation along the Y-axis
rotateZ(angle)Defines a 3D rotation along the Z-axis
skew(x-angle,y-angle)Defines a 2D skew transformation along the X- and the Y-axis
skewX(angle)Defines a 2D skew transformation along the X-axis
skewY(angle)Defines a 2D skew transformation along the Y-axis
perspective(n)Defines a perspective view for a 3D transformed element
transform-origin

The transform-origin property allows you to change the position of transformed elements.

2D transformations can change the x- and y-axis of an element. 3D transformations can also change the z-axis of an element.

Note: This property must be used together with the transform property.

transform-origin: 20% 40%;

 

ValueDescription
x-axisDefines where the view is placed at the x-axis.
Possible values: left, center, right, length, %
y-axisDefines where the view is placed at the y-axis.
Possible values: top, center, bottom, length, %
z-axisDefines where the view is placed at the z-axis (for 3D transformations).
Possible values: length
transform-style

The transform-style property specifies how nested elements are rendered in 3D space.

Note: This property must be used together with the transform property.

transform-style: preserve-3d;

 

ValueDescription
flatSpecifies that child elements will NOT preserve its 3D position. This is default
preserve-3dSpecifies that child elements will preserve its 3D position

Transition

transition

The transition property is a shorthand property for:

  • transition-property

  • transition-duration

  • transition-timing-function

  • transition-delay

Note: Always specify the transition-duration property, otherwise the duration is 0s, and the transition will have no effect.

transition: width 2s;

transition-property

The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes).

Tip: A transition effect could typically occur when a user hover over an element.

transition-property: width;

 

ValueDescription
noneNo property will get a transition effect
allDefault value. All properties will get a transition effect
propertyDefines a comma separated list of CSS property names the transition effect is for
transition-duration

The transition-duration property specifies how many seconds (s) or milliseconds (ms) a transition effect takes to complete.

transition-duration: 5s;

 

ValueDescription
timeSpecifies how many seconds or milliseconds a transition effect takes to complete. Default value is 0s, meaning there will be no effect
transition-timing-function

The transition-timing-function property specifies the speed curve of the transition effect.

This property allows a transition effect to change speed over its duration.

transition-timing-function: linear;

 

ValueDescription
easeDefault value. Specifies a transition effect with a slow start, then fast, then end slowly (equivalent to cubic-bezier(0.25,0.1,0.25,1))
linearSpecifies a transition effect with the same speed from start to end (equivalent to cubic-bezier(0,0,1,1))
ease-inSpecifies a transition effect with a slow start (equivalent to cubic-bezier(0.42,0,1,1))
ease-outSpecifies a transition effect with a slow end (equivalent to cubic-bezier(0,0,0.58,1))
ease-in-outSpecifies a transition effect with a slow start and end (equivalent to cubic-bezier(0.42,0,0.58,1))
step-startEquivalent to steps(1, start)
step-endEquivalent to steps(1, end)
steps(int,start|end)Specifies a stepping function, with two parameters. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, is either the value "start" or "end", and specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value "end"
cubic-bezier(n,n,n,n)Define your own values in the cubic-bezier function. Possible values are numeric values from 0 to 1
transition-delay

The transition-delay property specifies when the transition effect will start.

The transition-delay value is defined in seconds (s) or milliseconds (ms).

transition-delay: 2s;

 

ValueDescription
timeSpecifies the number of seconds or milliseconds to wait before the transition effect will start

Other

@charset

The @charset rule specifies the character encoding used in the style sheet.

The @charset rule must be the first element in the style sheet and not be preceded by any character. If several @charsetrules are defined, only the first one is used. The @charset rule cannot be used inside a style attribute (on an HTML element), or inside the <style> element where the character set of the HTML page is relevant.

@charset "UTF-8";

 

ValueDescription
charsetSpecifies the character encoding to use
@font-face

With the @font-face rule, web designers do not have to use one of the "web-safe" fonts anymore.

In the @font-face rule you must first define a name for the font (e.g. myFirstFont), and then point to the font file.

To use the font for an HTML element, refer to the name of the font (myFirstFont) through the font-family property:

@font-face {

font-family: myFirstFont;

src: url(sansation_light.woff);

}

 

Font DescriptorValueDescription
font-familynameRequired. Defines the name of the font.
srcURLRequired. Defines the URL(s) where the font should be downloaded from
font-stretchnormal
condensed
ultra-condensed
extra-condensed
semi-condensed
expanded
semi-expanded
extra-expanded
ultra-expanded
Optional. Defines how the font should be stretched. Default value is "normal"
font-stylenormal
italic
oblique
Optional. Defines how the font should be styled. Default value is "normal"
font-weightnormal
bold
100
200
300
400
500
600
700
800
900
Optional. Defines the boldness of the font. Default value is "normal"
unicode-rangeunicode-rangeOptional. Defines the range of unicode characters the font supports. Default value is "U+0-10FFFF"
@import

The @import rule allows you to import a style sheet into another style sheet.

The @import rule must be at the top of the document (but after any @charset declaration).

The @import rule also supports media queries, so you can allow the import to be media-dependent.

@import "navigation.css"; /* Using a string */

or

@import url("navigation.css"); /* Using a url */

 

ValueDescription
url|stringA url or a string representing the location of the resource to import. The url may be absolute or relative
list-of-mediaqueriesA comma-separated list of media queries conditioning the application of the CSS rules defined in the linked URL
@media

The @media rule is used in media queries to apply different styles for different media types/devices.

Media queries can be used to check many things, such as:

  • width and height of the viewport

  • width and height of the device

  • orientation (is the tablet/phone in landscape or portrait mode?)

  • resolution

Using media queries are a popular technique for delivering a tailored style sheet (responsive web design) to desktops, laptops, tablets, and mobile phones.

You can also use media queries to specify that certain styles are only for printed documents or for screen readers (mediatype: print, screen, or speech).

In addition to media types, there are also media features. Media features provide more specific details to media queries, by allowing to test for a specific feature of the user agent or display device. For example, you can apply styles to only those screens that are greater, or smaller, than a certain width.

Syntax:

@media not|only mediatype and (mediafeature and|or|not mediafeature) {

CSS-Code;

}

 

Example:

@media only screen and (max-width: 600px) {

body {

background-color: lightblue;

}

}

 

Media Types

ValueDescription
allDefault. Used for all media type devices
printUsed for printers
screenUsed for computer screens, tablets, smart-phones etc.
speechUsed for screenreaders that "reads" the page out loud

 

Media Features

ValueDescription
any-hoverDoes any available input mechanism allow the user to hover over elements? (added in Media Queries Level 4)
any-pointerIs any available input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4)
aspect-ratioThe ratio between the width and the height of the viewport
colorThe number of bits per color component for the output device
color-gamutThe approximate range of colors that are supported by the user agent and output device (added in Media Queries Level 4)
color-indexThe number of colors the device can display
gridWhether the device is a grid or bitmap
heightThe viewport height
hoverDoes the primary input mechanism allow the user to hover over elements? (added in Media Queries Level 4)
inverted-colorsIs the browser or underlying OS inverting colors? (added in Media Queries Level 4)
light-levelCurrent ambient light level (added in Media Queries Level 4)
max-aspect-ratioThe maximum ratio between the width and the height of the display area
max-colorThe maximum number of bits per color component for the output device
max-color-indexThe maximum number of colors the device can display
max-heightThe maximum height of the display area, such as a browser window
max-monochromeThe maximum number of bits per "color" on a monochrome (greyscale) device
max-resolutionThe maximum resolution of the device, using dpi or dpcm
max-widthThe maximum width of the display area, such as a browser window (Used Primarily)
min-aspect-ratioThe minimum ratio between the width and the height of the display area
min-colorThe minimum number of bits per color component for the output device
min-color-indexThe minimum number of colors the device can display
min-heightThe minimum height of the display area, such as a browser window
min-monochromeThe minimum number of bits per "color" on a monochrome (greyscale) device
min-resolutionThe minimum resolution of the device, using dpi or dpcm
min-widthThe minimum width of the display area, such as a browser window
monochromeThe number of bits per "color" on a monochrome (greyscale) device
orientationThe orientation of the viewport (landscape or portrait mode)
overflow-blockHow does the output device handle content that overflows the viewport along the block axis (added in Media Queries Level 4)
overflow-inlineCan content that overflows the viewport along the inline axis be scrolled (added in Media Queries Level 4)
pointerIs the primary input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4)
resolutionThe resolution of the output device, using dpi or dpcm
scanThe scanning process of the output device
scriptingIs scripting (e.g. JavaScript) available? (added in Media Queries Level 4)
updateHow quickly can the output device modify the appearance of the content (added in Media Queries Level 4)
widthThe viewport width
all

The all property resets all properties, apart from unicode-bidi and direction, to their initial or inherited value.

all: initial;

 

ValueDescription
initialChanges all the properties applied to the element or the element's parent to their initial value
inheritChanges all the properties applied to the element or the element's parent to their parent value
unsetChanges all the properties applied to the element or the element's parent to their parent value if they are inheritable or to their initial value if not
content

The content property is used with the ::before and ::after pseudo-elements, to insert generated content.

content: " (" attr(href) ")";

 

ValueDescription
normalDefault value. Sets the content, if specified, to normal, which default is "none" (which is nothing)
noneSets the content, if specified, to nothing
counterSets the content as a counter
attr(attribute)Sets the content as one of the selector's attribute
stringSets the content to the text you specify
open-quoteSets the content to be an opening quote
close-quoteSets the content to be a closing quote
no-open-quoteRemoves the opening quote from the content, if specified
no-close-quoteRemoves the closing quote from the content, if specified
url(url)Sets the content to be some kind of media (an image, a sound, a video, etc.)
counter-increment

The counter-increment property increases or decreases the value of one or more CSS counters.

The counter-increment property is usually used together with the counter-reset property and the content property.

body {

/* Set "my-sec-counter" to 0 */

counter-reset: my-sec-counter;

}

 

h2::before {

/* Increment "my-sec-counter" by 1 */

counter-increment: my-sec-counter;

content: "Section " counter(my-sec-counter) ". ";

}

 

ValueDescription
noneDefault value. No counters will be incremented
id numberThe id defines which counter to increment. The number sets how much the counter will increment on each occurrence of the selector. The default increment is 1. Negative values are allowed. If idrefers to a counter that has not been initialized by counter-reset, the default initial value is 0
counter-reset

The counter-reset property creates or resets one or more CSS counters.

The counter-reset property is usually used together with the counter-increment property and the content property.

ValueDescription
noneDefault value. No counters will be incremented
id numberThe id defines which counter to increment. The number sets how much the counter will increment on each occurrence of the selector. The default increment is 1. Negative values are allowed. If idrefers to a counter that has not been initialized by counter-reset, the default initial value is 0
image-rendering

The image-rendering property specifies the type of algorithm to be used for image scaling.

Note: This property has no effect on images that are not scaled.

image-rendering: high-quality;

 

ValueDescription
autoLet the browser choose the scaling algorithm. This is default
smoothUse an algorithm that smooth out the colors in the image
high-qualitySame as smooth, but with a preference for higher-quality scaling
crisp-edgesUse an algorithm that will preserve the contrast and edges in the image
pixelatedIf the image is scaled up, the nearest-neighbor algorithm is used, so the image will appear as being composed of large pixels. If the image is scaled down, it will be the same as auto
unicode-bidi

Used together with the direction property to set or return whether the text should be overridden to support multiple languages in the same document

ValueDescription
initialSets this property to its default value.
inheritInherits this property from its parent element.

CSS Selectors

.class

The .class selector selects elements with a specific class attribute.

To select elements with a specific class, write a period (.) character, followed by the name of the class.

You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.) character, followed by the name of the class (look at Example 1 below).

HTML elements can also refer to more than one class (look at Example 2 below).

.intro {}

 

.class1.class2Selects all elements with both name1 and name2 set within its class attribute
.class1 .class2Selects all elements with name2 that is a descendant of an element with name1
#id

The #id selector styles the element with the specified id.

#firstname {}

*

The * selector selects all elements.

The * selector can also select all elements inside another element (See "More Examples").

* {}

element

The element selector selects all elements with the specified element name.

p {}

 

element.classThe element.class selector is used to select the specified element with the the specified class.
p.intro {}
element,elementTo style several elements with the same style, separate each element name with a comma.
h2, p {}
element elementThe element element selector is used to select elements inside elements.
div p {}
element>elementThe element>element selector is used to select elements with a specific parent.
Note: Elements that are not directly a child of the specified parent, are not selected.
div > p {}
element+elementThe element+element selector is used to select an element that is directly after another specific element.
div + p {}
element1~element2The element1~element2 selector matches occurrences of element2 that are preceded by element1.
Both elements must have the same parent, but element2 does not have to be immediately preceded by element1.
p ~ ul {}
[attribute]

The [attribute] selector is used to select elements with the specified attribute.

a[target] {}

 

[attribute=value]The [attribute=value] selector is used to select elements with the specified attribute and value.
a[target=_blank] {}
[attribute~=value]The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.
[title~=flower] {}
[attribute|=value]The [attribute|=value] selector is used to select elements with the specified attribute starting with the specified value.
Note: The value has to be a whole word, either alone, like lang="en", or followed by a hyphen( - ), like lang="en-us".
[lang|=en] {}
[attribute^=value]The [attribute^=value] selector matches every element whose attribute value begins with a specified value.
div[class^="test"] {}
[attribute$=value]The [attribute$=value] selector matches every element whose attribute value ends with a specified value.
div[class$="test"] {}
[attribute*=value]The [attribute*=value] selector matches every element whose attribute value containing a specified value.
div[class*="test"] {}
:active

The :active selector is used to select and style the active link.

A link becomes active when you click on it.

Tip: The :active selector can be used on all elements, not only links.

Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :hoverselector to style links when you mouse over them.

Note: :active MUST come after :hover (if present) in the CSS definition in order to be effective!

a:active {}

:visited

The :visited selector is used to select visited links.

Browsers limits the styles that can be set for a:visited links, due to security issues.

Allowed styles are:

  • color

  • background-color

  • border-color (and border-color for separate sides)

  • outline color

  • column-rule-color

  • the color parts of fill and stroke

All other styles are inherited from a:link.

a:visited {}

:hover

The :hover selector is used to select elements when you mouse over them.

Tip: The :hover selector can be used on all elements, not only on links.

Note: :hover MUST come after :link and :visited (if they are present) in the CSS definition, in order to be effective!

a:hover {}

::after

The ::after selector inserts something after the content of each selected element(s).

Use the content property to specify the content to insert.

p::after {

content: " - Remember this";

}

::before

The ::before selector inserts something before the content of each selected element(s).

Use the content property to specify the content to insert.

p::before {

content: "Read this: ";

}

:first-child

The :first-child selector is used to select the specified selector, only if it is the first child of its parent.

p:first-child {}

:nth-child(n)

The :nth-child(n) selector matches every element that is the nth child of its parent.

n can be a number, a keyword (odd or even), or a formula (like an + b).

div:nth-child(2) {}

:nth-last-child(n)

The :nth-last-child(n) selector matches every element that is the nth child, regardless of type, of its parent, counting from the last child.

p:nth-last-child(2) {}

:last-child

The :last-child selector matches every element that is the last child of its parent.

Tip: p:last-child is equal to p:nth-last-child(1).

p:last-child {}

:only-child

The :only-child selector matches every element that is the only child of its parent.

p:only-child {}

::first-letter

The ::first-letter selector is used to add a style to the first letter of the specified selector.

Note: The following properties can be used with ::first-letter:

  • font properties

  • color properties

  • background properties

  • margin properties

  • padding properties

  • border properties

  • text-decoration

  • vertical-align (only if float is 'none')

  • text-transform

  • line-height

  • float

  • clear

Note: The ::first-letter selector can only be used with block-level elements.

p::first-letter {}

::first-line

The ::first-line selector is used to add a style to the first line of the specified selector.

Note: The following properties can be used with ::first-line:

  • font properties

  • color properties

  • background properties

  • word-spacing

  • letter-spacing

  • text-decoration

  • vertical-align

  • text-transform

  • line-height

  • clear

Note: The ::first-line selector can only be used with block-level elements.

p::first-line {}

:first-of-type

The :first-of-type selector matches every element that is the first child, of a particular type, of its parent.

Tip: This is the same as :nth-of-type(1).

p:first-of-type {}

:nth-of-type(n)

The :nth-of-type(n) selector matches every element that is the nth child, of the same type (tag name), of its parent.

div:nth-of-type(2) {}

:nth-last-of-type(n)

The :nth-last-of-type(n) selector matches every element that is the nth child, of a particular type, of its parent, counting from the last child.

p:nth-last-of-type(2) {}

:last-of-type

The :last-of-type selector matches every element that is the last child, of a particular type, of its parent.

Tip: This is the same as :nth-last-of-type(1).

p:last-of-type {}

:only-of-type

The :only-of-type selector matches every element that is the only child of its type, of its parent.

p:only-of-type {}

:not(selector)

The :not(selector) selector matches every element that is NOT the specified element/selector.

:not(p) {}

:root

The :root selector matches the document's root element.

In HTML, the root element is always the html element.

:root {}

:lang(language)

The :lang() selector is used to select elements with a lang attribute with the specified value.

p:lang(it) {}

:fullscreen

The :fullscreen selector is used to select the element(s) that is in full-screen mode.

:fullscreen {}

::marker

The ::marker selector selects the marker of a list item. (Bullet Points)

This selector works on any element set to display:list-item.

::marker {}

::selection

The ::selection selector matches the portion of an element that is selected by a user (Highlighted).

Only a few CSS properties can be applied to the ::selection selector: color, background, cursor, and outline.

::selection {}

:empty

The :empty selector matches every element that has no children (including text nodes).

p:empty {}

:target

URLs with an # followed by an anchor name link to a certain element within a document. The element being linked to is the target element.

The :target selector can be used to style the current active target element.

:target {}

:required

The :required selector selects form elements which are required.

Form elements with a required attribute are defined as required.

Note: The :required selector only applies to the form elements: input, select and textarea.

input:required {}

:optional

The :optional selector selects form elements which are optional.

Form elements with no required attribute are defined as optional.

Note: The :optional selector only applies to the form elements: input, select and textarea.

input:optional {}

::placeholder

The ::placeholder selector selects form elements with placeholder text, and let you style the placeholder text.

The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field.

Tip: The default color of the placeholder text is light grey in most browsers.

::placeholder {}

:read-only

The :read-only selector selects elements which are "readonly".

Form elements with a "readonly" attribute are defined as "readonly".

input:read-only {}

:read-write

The :read-write selector selects form elements which are "readable" and "writeable".

Form elements with no "readonly" attribute, and no "disabled" attribute are defined as "read-" and "write-able".

input:read-write {}

:focus

The :focus selector is used to select the element that has focus.

Tip: The :focus selector is allowed on elements that accept keyboard events or other user inputs.

:in-range

The :in-range selector selects all elements with a value that is within a specified range.

Note: The :in-range selector only works for input elements with min and/or max attributes!

Tip: Use the :out-of-range selector to select all elements with a value that is outside a specified range.

input:in-range {}

:out-of-range

The :out-of-range selector selects all elements with a value that is outside a specified range.

Note: The :out-of-range selector only works for input elements with min and/or max attributes!

input:out-of-range {}

:checked

The :checked selector matches every checked <input> element (only for radio buttons and checkboxes) and <option> element.

input:checked {}

:default

The :default selector selects the default form element in a group of related elements.

The :default selector can only be used on <button>, <input type="checkbox">, <input type="radio">, and <option> elements

input:default {}

:disabled

The :disabled selector matches every disabled element (mostly used on form elements).

input[type="text"]:disabled {}

:enabled

The :enabled selector matches every enabled element (mostly used on form elements).

input[type="text"]:enabled {}

:indeterminate

The :indeterminate selector selects form elements that are in an indeterminate state.

The :indeterminate selector can only be used on <input type="checkbox">, <input type="radio">, and <progress> elements.

Note: Checkboxes cannot be indeterminate with HTML - it is a property of the checkbox object, which can be set to true by JavaScript.

Radio buttons are indeterminate when all radio buttons with the same name value in the form are unchecked.

input:indeterminate {}

:valid

The :valid selector selects form elements with a value that validates according to the element's settings.

Note: The :valid selector only works for form elements with limitations, such as input elements with min and max attributes, email fields with a legal email, or number fields with a numeric value, etc.

input:valid {}

:invalid

The :valid selector selects form elements with a value that validates according to the element's settings.

Note: The :valid selector only works for form elements with limitations, such as input elements with min and max attributes, email fields with a legal email, or number fields with a numeric value, etc.

input:valid {}

CSS Functions

attr()

The attr() function returns the value of an attribute of the selected elements.

content: " (" attr(href) ")";

calc()

The calc() function performs a calculation to be used as the property value.

width: calc(100% - 100px);

counter()

The counter() function returns the current value of the named counter, as a string.

counter-increment: section;

content: "Section " counter(section) ": ";

 

ValueDescription
counternameRequired. The name of the counter (which is the same name used for the counter-reset and counter-increment properties)
counterstyleOptional. The style of the counter (can be a list-style-type value)
cubic-bezier()

The cubic-bezier() function defines a Cubic Bezier curve.

A Cubic Bezier curve is defined by four points P0, P1, P2, and P3. P0 and P3 are the start and the end of the curve and, in CSS these points are fixed as the coordinates are ratios. P0 is (0, 0) and represents the initial time and the initial state, P3 is (1, 1) and represents the final time and the final state.

The cubic-bezier() function can be used with the animation-timing-function property and the transition-timing-functionproperty.

transition-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1);

max()

The max() function uses the largest value, from a comma-separated list of values, as the property value.

width: max(50%, 300px);

 

ValueDescription
value1, value2, ...Required. A list of comma-separated values - where the largest value is chosen
min()

The min() function uses the smallest value, from a comma-separated list of values, as the property value.

width: min(50%, 300px);

 

ValueDescription
value1, value2, ...Required. A list of comma-separated values - where the largest value is chosen
var()

The var() function is used to insert the value of a CSS variable.

background-color: var(--main-bg-color)

 

:root {

--main-bg-color: coral;

}

 

#div1 {

background-color: var(--main-bg-color);

padding: 5px;

}

 

ValueDescription
nameRequired. The variable name (must start with two dashes)
valueOptional. The fallback value (used if the variable is not found)
rgb()

The rgb() function define colors using the Red-green-blue (RGB) model.

An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of that color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%).

For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set to its highest value (255) and the others are set to 0.

background-color:rgb(0,0,255);

 

ValueDescription
redDefines the intensity of red as an integer between 0 and 255, or as a percentage value between 0% and 100%
greenDefines the intensity of green as an integer between 0 and 255, or as a percentage value between 0% and 100%
blueDefines the intensity of blue as an integer between 0 and 255, or as a percentage value between 0% and 100%
rgba()

The rgba() function define colors using the Red-green-blue-alpha (RGBA) model.

RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity of the color.

background-color:rgba(0,0,255,0.3);

 

ValueDescription
redDefines the intensity of red as an integer between 0 and 255, or as a percentage value between 0% and 100%
greenDefines the intensity of green as an integer between 0 and 255, or as a percentage value between 0% and 100%
blueDefines the intensity of blue as an integer between 0 and 255, or as a percentage value between 0% and 100%
alphaDefines the opacity as a number between 0.0 (fully transparent) and 1.0 (fully opaque)
hsl()

The hsl() function define colors using the Hue-saturation-lightness model (HSL).

HSL stands for hue, saturation, and lightness - and represents a cylindrical-coordinate representation of colors.

background-color:hsl(120,100%,75%);

hsla()

The hsla() function define colors using the Hue-saturation-lightness-alpha model (HSLA).

HSLA color values are an extension of HSL color values with an alpha channel - which specifies the opacity of the color.

background-color:hsla(120,100%,25%,0.3);

linear-gradient()

The linear-gradient() function sets a linear gradient as the background image.

To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.

background-image: linear-gradient(to bottom right, red , blue);

 

ValueDescription
directionDefines a starting point and a direction (or an angle) along with the gradient effect.
color-stop1, color-stop2,...Color stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis).
repeating-linear-gradient()

The repeating-linear-gradient() function is used to repeat linear gradients.

background-image: repeating-linear-gradient(red, yellow 10%, green 20%);

 

ValueDescription
angleDefines an angle of direction for the gradient. From 0deg to 360deg. Default is 180deg.
side-or-cornerDefines the position of the starting-point of the gradient line. It consists of two keywords: the first one indicates the horizontal side, left or right, and the second one the vertical side, top or bottom. The order is not relevant and each of the keyword is optional.
color-stop1, color-stop2,...Color stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis).
radial-gradient()

The radial-gradient() function sets a radial gradient as the background image.

A radial gradient is defined by its center.

To create a radial gradient you must define at least two color stops.

background-image: radial-gradient(red, green, blue);

 

ValueDescription
shapeDefines the shape of the gradient.

Possible values:
ellipse (default)
circle
sizeDefines the size of the gradient.

Possible values:
farthest-corner (default)
closest-side
closest-corner
farthest-side
positionDefines the position of the gradient. Default is "center"
start-color, ..., last-colorColor stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis).
repeating-radial-gradient()

The repeating-radial-gradient() function is used to repeat radial gradients.

background-image: repeating-radial-gradient(red, yellow 10%, green 15%);

 

ValueDescription
shapeDefines the shape of the gradient.

Possible values:
ellipse (default)
circle
sizeDefines the size of the gradient.

Possible values:
farthest-corner (default)
closest-side
closest-corner
farthest-side
positionDefines the position of the gradient. Default is "center"
start-color, ..., last-colorColor stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis).
conic-gradient()

The conic-gradient() function sets a conic gradient as the background image.

A conic gradient is a gradient with color transitions rotated around a center point.

To create a conic gradient you must define at least two color stops.

background-image: conic-gradient(red, yellow, green);

 

ValueDescription
from angleOptional. The entire conic gradient is rotated by this angle. Default value is 0deg
at positionOptional. Specifies the gradient center of the conic gradient. Default value is center
color degree, ..., color degreeColor stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a degree between 0 and 360 or a percent between 0% and 100%).
repeating-conic-gradient()

The repeating-conic-gradient() function is used to repeat conic gradients.

background-image: repeating-conic-gradient(red 10%, yellow 20%);

 

ValueDescription
from angleOptional. The entire conic gradient is rotated by this angle. Default value is 0deg
at positionOptional. Specifies the gradient center of the conic gradient. Default value is center
color degree, ..., color degreeColor stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a degree between 0 and 360 or a percent between 0% and 100%).