CSS reference – properties, selectors, functions
An overview of CSS properties, selectors, functions and rules with examples: sizing and the box model, flexbox, grid, fonts, colors, animations, selectors and responsive rules. The examples show the result – the previews are created directly from the code of the example. Each entry gives the initial value, whether the property is inherited and browser support according to MDN data.
247 entries
Sizing and the box model 25 entries
- aspect-ratio Sets the aspect ratio of an element.
- border Sets the border on all four sides of an element at once: the width, the line style and the color, in any order.
- border-color Sets the color of a border – with one value for all sides, or with up to four for each side separately.
- border-image A border made of an image or a gradient instead of a line.
- border-radius Rounds the corners of an element – the background, the border and the shadow.
- border-style Sets the kind of line the border is drawn with – solid, dashed, dotted, double… It is the only part of a border without which nothing is drawn: the default…
- border-width Sets the thickness of a border.
- box-sizing Decides what width and height refer to: only the content (the default content-box), or the whole element including padding and border (border-box).
- height Sets the height of an element.
- inline-size and block-size Logical dimensions: inline-size is the size in the direction of the line of text, block-size in the direction in which lines are added.
- Length units (px, em, rem, %, vw…) Lengths in CSS are absolute (px) or relative – to the font (em, rem), to the viewport (vw, vh), to a container (cqi) or to the parent (%).
- margin Sets the outer margin – free space around the element, outside its border and background.
- margin-inline and margin-block Logical margins: margin-inline sets the margin at the start and end of the line (left and right in English), margin-block above and below a block.
- max-height Sets the maximum height of an element.
- max-width Sets the maximum width of an element.
- min-height Sets the minimum height of an element.
- min-width Sets the minimum width below which the element does not shrink – not even when it has a smaller width or when its parent gets narrower.
- object-fit Sets how the content of an image or video adapts to the dimensions of the element when their aspect ratios differ.
- object-position Moves the content of an image or video inside the element.
- outline Draws an outline around an element, outside its border.
- outline-offset Moves the outline (outline) away from the edge of the border of the element.
- overflow Decides what happens to content that does not fit into an element: it stays visible beyond the edge, it is clipped, or the element gets a scrollbar.
- padding Sets the inner spacing – the space between the content and the border of the element.
- padding-inline and padding-block Logical padding: padding-inline at the start and end of the line (left and right in English), padding-block at the top and bottom.
- width Sets the width of an element.
Positioning and display 8 entries
- clear Prevents an element from standing next to floating elements (float): the element moves below them.
- display Sets how an element is shown on the page: as a block across the full width, inline with the text, as a flex or grid container, or not at all.
- float Moves an element to the left or right side of its parent and lets the surrounding text and inline elements flow around it – typically an image in an article.
- inset A shorthand that sets top, right, bottom and left at once.
- position Sets how an element is positioned: in the normal flow of the page, shifted, taken out of the flow and placed relative to a parent or the window, or “stuck”…
- top, right, bottom, left Four properties that set the position of an element with a position (other than static).
- visibility Hides an element, but its place on the page stays empty – the surrounding elements do not move.
- z-index Sets the order of overlapping elements “towards the viewer”: the element with the higher number is on top.
Flexbox and alignment 18 entries
- align-content Distributes the free space between the lines of a wrapping flexbox (flex-wrap: wrap) or between the rows of a grid.
- align-items Aligns the items of a flex container on the cross axis – vertically for a row (flex-direction: row). align-items: center is the simplest way to center…
- align-self Overrides the align-items of the container for one item: the others can be stretched and this one at the top, or all at the top and one at the bottom.
- flex A shorthand that sets how a flexbox item grows and shrinks: flex-grow (its share of the free space), flex-shrink (its share when shrinking) and flex-basis…
- flex-basis Sets the initial size of an item on the main axis (the width in a row) that flexbox starts from.
- flex-direction Sets the main axis of a flex container – whether the items are laid out next to each other or below each other, and from which end. justify-content, flex-grow…
- flex-flow A shorthand that sets flex-direction (the direction) and flex-wrap (wrapping) at once. flex-flow: row wrap means items next to each other with wrapping.
- flex-grow Sets how large a share of the free space in the container the item gets on top of its initial size (flex-basis).
- flex-shrink Sets how an item takes part in shrinking when the items do not fit into the container.
- flex-wrap Sets whether flexbox items that do not fit on one line wrap onto the next line.
- gap Sets the gap between the items of a flexbox, a grid or the columns of text – not before the first and after the last item.
- justify-content Distributes the items of a flex container along the main axis (horizontally with flex-direction: row) – it shares out the free space left over by the items.
- justify-items Aligns all grid items on the inline axis (horizontally in English) inside their cells.
- justify-self Aligns one grid item on the inline axis (horizontally) in its cell, overriding the justify-items of the container.
- order Changes the order in which a flexbox or grid item is shown.
- place-content A shorthand that sets align-content (the distribution of rows) and justify-content (the distribution of columns, in flexbox of the items on the main axis)…
- place-items A shorthand that sets align-items (vertical alignment) and justify-items (horizontal alignment) at once.
- place-self A shorthand that sets align-self (vertical alignment) and justify-self (horizontal) for one item at once. place-self: center centers the item in its grid…
Grid 13 entries
- fit-content() A grid track size by content with an upper limit: short content = a narrow column, long content = a column at most as wide as the limit, with the text…
- grid-area Places a grid item into an area: either by a name from grid-template-areas, or by the numbers of the grid lines.
- grid-auto-columns Sets the width of the columns the grid creates by itself – mainly with grid-auto-flow: column, where each further item adds a column, or when an item refers…
- grid-auto-flow Sets how a grid places items that have no given position: by rows (the default) or by columns, and whether it should go back and fill holes left by larger…
- grid-auto-rows Sets the height of the rows the grid creates by itself – when there are more items than the rows defined by grid-template-rows (or when no rows are defined…
- grid-column Sets which grid columns an item stretches across – a shorthand for grid-column-start and grid-column-end.
- grid-row Sets which grid rows an item stretches across – a shorthand for grid-row-start and grid-row-end.
- grid-template A shorthand for grid-template-rows, grid-template-columns and grid-template-areas.
- grid-template-areas Draws the layout of a grid with names: each string is one row, each word one cell.
- grid-template-columns Sets the number and width of the columns of a grid container.
- grid-template-rows Sets the number and height of the rows of a grid container, with the same syntax as grid-template-columns for columns.
- minmax() A function for the size of a grid track (a column or a row): the track will not be smaller than the first value or larger than the second.
- repeat() A short way to write repeating grid tracks: repeat(4, 1fr) is the same as 1fr 1fr 1fr 1fr.
Fonts 12 entries
- font A shorthand that sets font-style, font-variant, font-weight, font-stretch, font-size, line-height and font-family in one declaration.
- font-display A descriptor inside @font-face that controls what happens before a web font downloads: whether the text is invisible for a while, or shown at once in a…
- @font-face Loads a web font from a file and names it; the name is then used in font-family.
- font-family Sets the font of text as a comma-separated list.
- font-feature-settings Low-level access to OpenType font features using four-letter tags: ligatures ("liga"), small caps ("smcp"), alternative shapes ("ss01")… It is useful for…
- font-size Sets the size of the font.
- font-style Switches between upright text and italics.
- font-variant-numeric Turns on alternative digit shapes that the font contains.
- font-weight Sets the weight of the font.
- letter-spacing Adds (or removes) space between characters – tracking in typography.
- line-height Sets the height of a line of text – the line spacing.
- word-spacing Adds or removes space to the gaps between words.
Text and wrapping 19 entries
- direction Sets the base direction of text and inline elements: left to right, or right to left (Arabic, Hebrew, Persian).
- hyphens Turns on hyphenation of words at the end of a line by syllables.
- line-clamp and -webkit-line-clamp Limits a block of text to a given number of lines; the rest is hidden and the last line ends with an ellipsis “…”.
- overflow-wrap Allows breaking a word that does not fit on a line as a whole – typically a long URL, an email address or a word without spaces in a narrow column.
- quotes Sets which quotation marks the browser inserts for the <q> tag and for the open-quote and close-quote values of the content property.
- tab-size Sets how wide the tab character is in text that preserves spaces (<pre>, white-space: pre, pre-wrap).
- text-align Horizontally aligns the content of lines – text, images and other inline elements – inside a block element.
- text-decoration A shorthand for a line along text: an underline, an overline or a strikethrough, including its style (solid, wavy…), color and thickness.
- text-decoration-thickness Sets the thickness of the line from text-decoration.
- text-indent Indents the first line of text in a block element – like paragraphs in a book.
- text-overflow Sets how text that overflows the element is shown: with ellipsis a “…” appears at the end.
- text-shadow Adds a shadow to the letters of the text (not to the box of the element – box-shadow does that).
- text-transform Changes the case of letters when displayed – the text stays in the HTML as written.
- text-underline-offset Sets the distance of the underline from its default position (below the baseline).
- text-wrap Controls how text wraps into lines.
- vertical-align Vertically aligns an inline element (inline, inline-block, an image) relative to the line of text it stands in, or the content of a table cell.
- white-space Sets what the browser does with the spaces and line breaks from the source HTML and whether it may wrap text.
- word-break Changes the rules for where a line may break inside a word.
- writing-mode Sets whether the lines of text run horizontally or vertically, and in which direction they are added.
Colors and backgrounds 20 entries
- accent-color Sets the accent color of form controls drawn by the browser: checkboxes, radio buttons (radio), the input type="range" slider and the progress indicator.
- background A shorthand for all background properties: the color, image, position, size, repeat, attachment and the background-origin and background-clip areas.
- background-attachment Sets what the background is attached to: the element (scroll, the default), the browser window (fixed – the content scrolls over a still image) or the…
- background-blend-mode Blends the background layers of one element with each other – images, gradients and the background color.
- background-clip Clips the background (the color and the image) to a chosen area of the element: the default border-box reaches under the border.
- background-color The background color of an element.
- background-image An image in the background of an element – a file with url() or a gradient.
- background-origin Sets the area in which the background image is placed – background-position and the percentages in background-size are calculated from it.
- background-position The position of a background image in its area.
- background-repeat Sets whether and how a background image repeats when it is smaller than the element.
- background-size The size of a background image.
- caret-color The color of the blinking text cursor that shows where you will type – in input, textarea and elements with the contenteditable attribute.
- color Sets the color of text.
- color-mix() Mixes two colors in a given ratio, for example 60% blue and 40% white.
- color-scheme Tells the browser in which color schemes an element looks good.
- hsl() A color as a hue on the color wheel, a saturation and a lightness.
- light-dark() Returns the first color in the light and the second in the dark color scheme.
- oklch() A color in the OKLCH space, which matches human perception: the same lightness means the same perceived brightness for all hues.
- opacity Sets the opacity of the whole element including text, images and descendants: 1 is opaque, 0 fully transparent.
- rgb() A color from three components – red, green and blue – in the range 0–255 (or 0–100%).
Gradients, filters and clipping 14 entries
- backdrop-filter A filter on what is visible behind the element, not on the element itself.
- box-shadow Adds a shadow to an element.
- clip-path Clips an element to a shape – a circle, an ellipse, a polygon, a rectangle with rounding or any path.
- conic-gradient() A color gradient around a center – the color changes with the angle like the hand of a clock, not with the distance from the center.
- filter Graphic effects on the whole element including its content: blur, brightness, contrast, grayscale, sepia, a hue shift or a shadow following the shape.
- image-rendering How the browser rescales raster images – smoothly or with sharp pixel edges.
- image-set() A list of variants of one image for the browser to choose from – by the pixel density of the display (1x, 2x) or by the format it supports (type("image/avif")).
- isolation With the value isolate it turns the element into a separate stacking context without having to set position and z-index or change its look.
- linear-gradient() An image with a smooth transition of colors along a line.
- mask-image A mask from an image or a gradient: where the mask is opaque, the element is visible; where it is transparent, the element disappears.
- mix-blend-mode How the colors of an element blend with what lies below it – just like the layer blend modes in graphics editors.
- radial-gradient() A color gradient that starts in the center and spreads outwards in a circle or an ellipse.
- repeating-linear-gradient() The same syntax as linear-gradient(), only the color stops repeat until they fill the whole element.
- shape-outside The shape that text flows around a floating element (float) – a circle or a slanted edge instead of a rectangle, for example.
Transforms and animations 13 entries
- animation Runs an animation described by a @keyframes rule.
- backface-visibility Sets whether an element is visible when it is turned with its back to the viewer (around the x or y axis by more than 90°).
- cubic-bezier() and steps() A timing function sets how a transition or an animation progresses over its time – whether it accelerates, decelerates, overshoots the target and comes…
- @keyframes A named course of an animation: which property values apply at the start, at the end and at any intermediate steps.
- perspective The distance of the viewer from the plane of the page for the 3D transforms of descendants.
- rotate A rotation of an element like transform: rotate(), but in a separate property that is not overridden by a move or scaling.
- scale Scaling an element up or down like transform: scale(), in a separate property.
- @starting-style Styles a transition should start from when an element only just appears – it is newly inserted into the page, or it changes from display: none.
- transform Moves, rotates, scales or skews an element including its content.
- transform-origin The point an element rotates around and scales or skews from.
- transition When the value of a property changes (on hover, by adding a class from JavaScript, by resizing the window), the browser does not change it abruptly but…
- translate A move of an element like transform: translate(), but in a separate property.
- will-change A hint for the browser that a property of an element will soon start changing (typically transform or opacity in an animation).
Selectors and pseudo-classes 37 entries
- :active Applies for the duration of “pressing” an element – from pressing the mouse button over the element until releasing it.
- Attribute selector ([attribute]) Selects elements by whether they have an attribute, or by its value.
- :checked Applies to a checked <input type="checkbox">, a selected <input type="radio"> and a selected <option> in a <select>.
- Child combinator (>) Selects elements whose parent is an element matching the selector on the left – only one level down, not grandchildren.
- Class selector (.class) Selects elements that have the given class in their class attribute.
- Descendant combinator (space) Two selectors separated by a space select elements matching the second selector that lie anywhere inside an element matching the first one – as children…
- :disabled and :enabled :disabled selects a disabled form control – a field, a button, a list, an option – with the disabled attribute or inside a disabled group <fieldset disabled>.
- :empty Selects an element that has no child – no element and no text, not even a space.
- :first-child Selects an element that is the first among the children of its parent.
- :first-of-type and :last-of-type :first-of-type selects an element that is the first among siblings of the same type, :last-of-type the last one.
- :focus Applies to the element that currently receives keyboard input: a form field the user is typing into, or a link or button selected with the Tab key.
- :focus-visible Like :focus, but the browser itself decides whether the focus should be visible.
- :focus-within Applies to an element when it has focus itself or any of its descendants does.
- :has() Selects an element inside which (or after which) there is an element matching the selector in the parentheses.
- :hover Applies while the pointer of a mouse (or another pointing device) is over the element.
- ID selector (#id) Selects the element with the given id attribute, which should be unique on the page.
- :is() Selects an element that matches at least one selector in the parentheses.
- :lang() Selects elements whose content is in the given language.
- :last-child Selects an element that is the last among the children of its parent.
- :link and :visited :link selects links (<a> and <area> with an href attribute) whose URL the user has not visited yet, :visited those already visited.
- Next-sibling combinator (+) Selects the element that follows immediately after an element matching the selector on the left and has the same parent.
- :not() Selects elements that do not match any selector in the parentheses. li:not(:last-child) are all items except the last one, input:not([type="checkbox"])…
- :nth-child() Selects elements whose position among siblings (counted from 1) matches the formula An+B: 0, 1, 2… is substituted for n and the resulting positions are…
- :nth-last-child() Works like :nth-child(), only it counts positions from the end: :nth-last-child(1) is the last element, :nth-last-child(-n+2) the last two.
- :nth-of-type() Like :nth-child(), but it counts only siblings of the same type (the same element name). p:nth-of-type(2) is the second paragraph in the parent, even when…
- :only-child Selects an element that has no siblings in its parent (text and comments do not count).
- :placeholder-shown Applies to an <input> or <textarea> field that is currently showing placeholder text: it has a placeholder attribute and is empty.
- :required and :optional :required selects <input>, <select> and <textarea> fields with the required attribute, :optional those without it.
- :root Selects the root of the document – the <html> element in an HTML page.
- Selector list (,) Selectors separated by commas share one declaration block: h1, h2, h3 { … } is the same as three rules with the same content.
- Subsequent-sibling combinator (~) Like +, but it selects all following siblings, not just the one right after the element.
- :target Selects the element whose id matches the anchor in the page URL – after clicking a link <a href="#contact"> or opening the URL …/page/#contact it is the…
- Type selector (p, div…) A tag name without any other characters selects all elements of that type: p all paragraphs, a all links.
- Universal selector (*) The asterisk selects any element.
- :user-invalid and :user-valid Like :invalid and :valid, but they apply only after the user has worked with the field – changed the value and left the field, or tried to submit the form.
- :valid and :invalid :invalid selects a field whose value does not meet the rules from the HTML – an empty required field, a wrong email in type="email", a value outside min/max…
- :where() Selects an element that matches at least one selector in the parentheses – just like :is().
Pseudo-elements 8 entries
- ::backdrop A layer across the whole window that the browser inserts under an element in the top layer of the page: a modal dialog opened with showModal(), a fullscreen…
- ::before and ::after Creates an extra child inside an element – ::before before its content, ::after after it.
- ::file-selector-button Selects the “Choose file” button inside an <input type="file"> field.
- ::first-letter Selects the first letter (or digit) in the first line of a block element.
- ::first-line Selects the first line of text in a block element – as the browser has just wrapped it.
- ::marker Selects the marker of a list item – the bullet in a <ul>, the number in an <ol> or the triangle of a <summary>.
- ::placeholder Selects the placeholder text from the placeholder attribute – the gray hint that an <input> or <textarea> field shows while it is empty.
- ::selection Selects the part of the document the user has selected (with the mouse, a finger or the keyboard).
Custom properties, calculations and the cascade 17 entries
- all A shorthand for all CSS properties except direction, unicode-bidi and custom properties (--*).
- attr() Reads an attribute of an element and inserts its value into CSS.
- calc() Calculates a value from addition, subtraction, multiplication and division – even between different units that cannot be added otherwise: calc(100% - 40px)…
- clamp() Uses the preferred value (the middle argument), but never smaller than the minimum or larger than the maximum.
- Custom properties (--*) The browser only remembers a property whose name starts with two hyphens – it draws nothing by itself.
- env() Inserts a value set by the browser or the device, not by the author of the page.
- !important A declaration with !important wins over all ordinary declarations of the same property – the specificity of the selector and the order do not matter, it…
- inherit, initial, unset, revert Global keywords apply to every property.
- @layer Cascade layers group rules and set their priority by the order of the layers: a rule from a later layer wins over a rule from an earlier one, even when…
- max() Uses the largest value from the list.
- min() Uses the smallest value from the list.
- Nesting rules (&) Rules can be written inside other rules, as only Sass or Less could before.
- @property An ordinary custom property is just text for the browser.
- @scope The styles inside apply only to elements in the root of the scope – for example inside a .card.
- Specificity and the cascade When several declarations target the same property of an element, the cascade decides step by step: by origin and !important (the browser, the user, the…
- url() A reference to a file in a style: a background image, a font in @font-face, a mask, a cursor or an SVG filter.
- var() Inserts the value of a custom property.
At-rules and media queries 10 entries
- @charset Tells the browser in which encoding an external CSS file is saved.
- @container Works like @media, except that it does not ask about the width of the window, but about the size of the nearest ancestor that is a container (has container-type).
- container-name Gives a container a name.
- container-type Makes an element a container whose size @container rules query and by which the cqi, cqw and cqh units are calculated.
- @import Inserts the content of another file into a style sheet, as if it were written there.
- @media The styles inside apply only when the device and the window meet the condition.
- @page Sets up the page when printing and saving to PDF – the paper size, the orientation and the margins.
- prefers-color-scheme A query for @media by the light or dark appearance the user has set in the system or in the browser.
- prefers-reduced-motion A query for @media that applies when the user has reduced animations in the system settings.
- @supports The styles inside apply only in a browser that understands the condition.
Lists, counters and tables 11 entries
- border-collapse Sets whether each table cell has its own border with a gap between cells (separate), or whether the borders of neighboring cells merge into one line (collapse).
- border-spacing Sets the gap between neighboring table cells and between the outer cells and the edge of the table.
- caption-side Sets whether the table caption <caption> stands above the table or below it.
- content Inserts generated content into the ::before and ::after pseudo-elements.
- counter-increment Increases a counter by 1 or by the given number on each element the rule targets.
- counter-reset Creates a counter (a named counter) on an element and sets it to the given value, 0 by default.
- counter() and counters() Write out the value of a counter created by counter-reset and increased by counter-increment.
- list-style A shorthand for list-style-type, list-style-position and list-style-image.
- list-style-position Sets where the bullet or number of an item lies.
- list-style-type Sets what list items are marked with – a dot, a square, a number, a letter, a Roman numeral or custom text.
- table-layout With auto the browser goes through the content of all cells and gives the columns a width by the longest text – a long word in a single cell stretches…
Columns, scrolling and more 22 entries
- appearance Sets whether a form control is drawn by the browser according to the system (auto), or without the native look (none) – then it can be styled like an ordinary…
- break-inside Tells the browser whether it may split an element where a column (columns) or a printed page ends.
- column-count Splits the content into a given number of columns of the same width.
- column-rule A vertical line between the columns of content split with columns or column-count.
- columns A shorthand for column-width and column-count.
- contain Promises the browser that what happens inside the element does not concern its surroundings.
- content-visibility Allows the browser not to calculate the layout and not to paint the content of an element until it is needed.
- cursor Sets what the mouse pointer looks like over an element.
- field-sizing Form fields have a fixed default size from the browser (textarea two lines, input about 20 characters).
- overscroll-behavior When a reader scrolls the content of a dialog, a menu or a chat and reaches its end, the browser starts scrolling the page under it.
- pointer-events With none the element stops reacting to the mouse and touch: clicks, hovering and scrolling with the wheel do not “see” it and go to the element below…
- resize Adds a handle in the bottom right corner of an element that can be dragged to change its size.
- scroll-behavior With smooth the browser does not jump to the target of an #anchor link or to the place given in scrollTo() and scrollIntoView(), but scrolls to it smoothly.
- scroll-margin When the page jumps to an element (an #anchor link, scrollIntoView(), scroll-snap snapping), it stops the given distance earlier.
- scroll-padding It is set on the scroll container – for the page on html.
- scroll-snap-align It is set on the items inside an element with scroll-snap-type.
- scroll-snap-type It is set on the scroll container (with overflow: auto or scroll).
- scrollbar-color Sets the color of the scrollbar: the first color is the thumb (the part you drag), the second the track below it.
- scrollbar-gutter On Windows and Linux the scrollbar takes up part of the width.
- scrollbar-width Sets the width of the scrollbar of an element: thin is narrower, none hides it, but the content can still be scrolled with the wheel, a finger and the…
- touch-action On a touch screen the browser scrolls the page with a finger and zooms it with two fingers.
- user-select Controls whether and how the content of an element can be selected with the mouse or a finger.
No entry matches your search.