CSS Reference
Every CSS property, selector, pseudo-class, at-rule, function and unit in one place. Concise, accurate pages with live examples, value tables and browser support notes.
Selectors
-
*The universal selector: matches every element. -
elementThe type selector: matches elements by tag name. -
.classThe class selector: matches elements with a given class. -
#idThe ID selector: matches the element with a given id. -
[attr]Attribute selectors: match by presence or value ([a], [a=v], ^=, $=, *=, ~=, |=, i, s). -
A BThe descendant combinator (a space). -
A > BThe child combinator. -
A + BThe next-sibling combinator. -
A ~ BThe subsequent-sibling combinator. -
A, BSelector lists and forgiving selector lists. -
&The nesting selector for CSS nesting. -
A || BThe column combinator (limited support). -
ns|elementNamespace separators for XML/SVG (rarely used).
Pseudo-classes
-
:hoverMatches when a pointer is over the element. -
:activeMatches while an element is being activated. -
:focusMatches the element with keyboard or pointer focus. -
:focus-visibleMatches focus that should show a visible indicator. -
:focus-withinMatches an element that contains the focused element. -
:linkMatches unvisited links. -
:visitedMatches visited links (with privacy limits). -
:any-linkMatches any link with an href. -
:targetMatches the element targeted by the URL fragment. -
:target-withinMatches an element containing the URL target (limited support). -
:first-childMatches the first child of its parent. -
:last-childMatches the last child of its parent. -
:only-childMatches an element that is the only child. -
:first-of-typeMatches the first sibling of its type. -
:last-of-typeMatches the last sibling of its type. -
:only-of-typeMatches the only sibling of its type. -
:nth-child()Matches elements by position with an+b and of S. -
:nth-last-child()Matches by position counting from the end. -
:nth-of-type()Matches by position among siblings of the same type. -
:nth-last-of-type()Same, counting from the end. -
:emptyMatches elements with no children. -
:rootMatches the document root element. -
:scopeMatches the scoping root (querySelector, @scope). -
:not()Matches elements that do not match the given selectors. -
:is()Matches any selector in a list; takes the highest specificity. -
:where()Like :is() but with zero specificity. -
:has()The relational pseudo-class: matches by descendants or siblings. -
:lang()Matches elements by language. -
:dir()Matches elements by text direction. -
:checkedMatches checked checkboxes, radios and selected options. -
:indeterminateMatches indeterminate form controls. -
:disabledMatches disabled form controls. -
:enabledMatches enabled form controls. -
:requiredMatches required form controls. -
:optionalMatches optional form controls. -
:validMatches controls whose value is valid. -
:invalidMatches controls whose value is invalid. -
:user-validValid after the user interacted. -
:user-invalidInvalid after the user interacted. -
:in-rangeMatches values within min and max. -
:out-of-rangeMatches values outside min and max. -
:read-onlyMatches elements the user cannot edit. -
:read-writeMatches elements the user can edit. -
:placeholder-shownMatches inputs showing placeholder text. -
:defaultMatches default form elements. -
:autofillMatches autofilled inputs. -
:fullscreenMatches the element in fullscreen. -
:modalMatches modal dialogs and fullscreen elements. -
:popover-openMatches open popovers. -
:openMatches open details, dialog or select (check support). -
:definedMatches defined (including custom) elements. -
:hostMatches the shadow host from inside its shadow tree. -
:state()Matches custom element states. -
:playingMatches media elements that are playing (limited support). -
:pausedMatches media elements that are paused (limited support). -
:picture-in-pictureMatches elements in picture-in-picture mode.
Pseudo-elements
-
::beforeGenerates content before an element's content. -
::afterGenerates content after an element's content. -
::first-letterStyles the first letter of a block. -
::first-lineStyles the first line of a block. -
::selectionStyles text the user has selected. -
::placeholderStyles the placeholder text of form fields. -
::markerStyles list item markers (bullets and numbers). -
::backdropStyles the layer behind top-layer elements. -
::file-selector-buttonStyles the button of file inputs. -
::cueStyles WebVTT captions and subtitles. -
::slotted()Styles slotted content from inside a shadow tree. -
::part()Styles parts a component exposes from its shadow tree. -
::highlight()Styles text ranges registered with the Highlight API. -
::spelling-errorStyles misspelled text (limited support). -
::view-transitionThe pseudo-element tree used by view transitions. -
::details-contentStyles the content area of details.
At-rules
-
@mediaApplies styles for media types and features. -
@containerApplies styles by container size or style. -
@supportsApplies styles when a feature is supported. -
@importImports another stylesheet. -
@charsetDeclares the stylesheet encoding. -
@font-faceDefines a custom font. -
@font-feature-valuesNames OpenType feature values. -
@keyframesDefines animation keyframes. -
@layerDeclares cascade layers. -
@propertyRegisters a custom property with a type. -
@namespaceDeclares an XML namespace. -
@pageStyles printed pages. -
@counter-styleDefines custom counter styles. -
@scopeScopes styles to a DOM subtree. -
@starting-styleSets starting styles for transitions. -
@view-transitionOpts in to cross-document view transitions. -
@position-tryDefines fallback positions for anchor positioning. -
@font-palette-valuesCustomizes color font palettes. -
@color-profileDefines a color profile (limited support).
Box Model and Sizing
-
displaySets the outer and inner display type of an element. -
widthSets the width of an element. -
heightSets the height of an element. -
min-widthSets the minimum width. -
max-widthSets the maximum width. -
min-heightSets the minimum height. -
max-heightSets the maximum height. -
box-sizingChooses how width and height are calculated. -
marginShorthand for the four margins. -
margin-topSets the top margin. -
margin-rightSets the right margin. -
margin-bottomSets the bottom margin. -
margin-leftSets the left margin. -
margin-trimTrims margins at container edges (limited support). -
paddingShorthand for the four paddings. -
padding-topSets the top padding. -
padding-rightSets the right padding. -
padding-bottomSets the bottom padding. -
padding-leftSets the left padding. -
aspect-ratioSets a preferred aspect ratio. -
overflowControls content that overflows the box. -
overflow-xControls horizontal overflow. -
overflow-yControls vertical overflow. -
overflow-wrapControls breaking of long words. -
overflow-clip-marginSets how far overflow:clip paints outside the box. -
overflow-anchorControls scroll anchoring. -
visibilityShows or hides an element without changing layout. -
containIsolates a subtree for performance. -
contain-intrinsic-sizeSets the size used when content is skipped. -
content-visibilitySkips rendering of offscreen content. -
field-sizingSizes form controls to their content. -
interpolate-sizeEnables animating to and from intrinsic sizes. -
floatFloats an element to the left or right. -
clearMoves an element below floats. -
box-decoration-breakControls box decoration across fragments.
Positioning and Stacking
-
positionSets how an element is positioned. -
topSets the top offset of a positioned element. -
rightSets the right offset of a positioned element. -
bottomSets the bottom offset of a positioned element. -
leftSets the left offset of a positioned element. -
insetShorthand for top, right, bottom and left. -
inset-blockLogical block-axis offsets. -
inset-inlineLogical inline-axis offsets. -
z-indexSets stacking order. -
isolationCreates a new stacking context. -
anchor-nameNames an element as an anchor. -
position-anchorChooses the anchor for anchor positioning. -
position-areaPlaces an element in a grid around its anchor. -
position-try-fallbacksLists fallback positions. -
position-visibilityHides an anchored element when its anchor is hidden. -
top layerExplains the top layer used by dialogs and popovers (concept page).
Flexbox
-
flexShorthand for flex-grow, flex-shrink and flex-basis. -
flex-basisSets the initial main size of a flex item. -
flex-directionSets the main axis direction. -
flex-flowShorthand for flex-direction and flex-wrap. -
flex-growSets how much an item grows. -
flex-shrinkSets how much an item shrinks. -
flex-wrapControls wrapping of flex lines. -
orderSets the visual order of items. -
justify-contentAligns items along the main axis. -
align-itemsAligns items on the cross axis. -
align-selfOverrides cross-axis alignment for one item. -
align-contentAligns wrapped lines or grid tracks. -
justify-itemsDefault justification of grid items. -
justify-selfJustifies one item inside its area. -
place-contentShorthand for align-content and justify-content. -
place-itemsShorthand for align-items and justify-items. -
place-selfShorthand for align-self and justify-self. -
gapShorthand for row-gap and column-gap. -
row-gapSets the gap between rows. -
column-gapSets the gap between columns.
Grid
-
gridShorthand for the grid template and auto properties. -
grid-templateShorthand for rows, columns and areas. -
grid-template-columnsDefines column tracks. -
grid-template-rowsDefines row tracks. -
grid-template-areasDefines named areas. -
grid-areaPlaces an item in an area or lines. -
grid-columnShorthand for column start and end. -
grid-column-startSets the start line of an item. -
grid-column-endSets the end line of an item. -
grid-rowShorthand for row start and end. -
grid-row-startSets the row start line. -
grid-row-endSets the row end line. -
grid-auto-columnsSizes implicit columns. -
grid-auto-rowsSizes implicit rows. -
grid-auto-flowControls the auto-placement algorithm. -
subgridLets a grid item inherit its parent's tracks. -
masonry layoutMasonry and grid-lanes layout status.
Multi-column and Fragmentation
-
columnsShorthand for column-width and column-count. -
column-countSets the number of columns. -
column-widthSets the ideal column width. -
column-fillControls how content is balanced across columns. -
column-spanLets an element span all columns. -
column-ruleShorthand for column rule width, style and color. -
column-rule-colorSets the column rule color. -
column-rule-styleSets the column rule style. -
column-rule-widthSets the column rule width. -
break-beforeControls breaks before a box. -
break-afterControls breaks after a box. -
break-insideControls breaks inside a box. -
orphansMinimum lines at the bottom of a page or column. -
widowsMinimum lines at the top of a page or column.
Typography
-
fontShorthand for font properties. -
font-familySets the font family list. -
font-sizeSets the font size. -
font-size-adjustAdjusts the font size by x-height. -
font-styleSets normal, italic or oblique. -
font-weightSets the font weight. -
font-stretchSets the font width. -
font-variantShorthand for font variants. -
font-variant-capsControls small caps. -
font-variant-numericControls numeric glyph variants. -
font-variant-ligaturesControls ligatures. -
font-feature-settingsLow-level OpenType features. -
font-variation-settingsSets variable font axes. -
font-optical-sizingControls optical sizing. -
font-kerningControls kerning. -
font-synthesisControls synthesized bold and italic. -
font-displayControls font loading display (an @font-face descriptor). -
font-paletteSelects a color font palette. -
line-heightSets the line height. -
letter-spacingSets spacing between letters. -
word-spacingSets spacing between words. -
text-alignAligns inline content. -
text-align-lastAligns the last line. -
text-indentIndents the first line. -
text-transformChanges text case. -
text-decorationShorthand for text decoration. -
text-decoration-lineSets underline, overline or line-through. -
text-decoration-colorSets the decoration color. -
text-decoration-styleSets solid, wavy and other styles. -
text-decoration-thicknessSets the decoration thickness. -
text-underline-offsetSets underline distance. -
text-underline-positionSets underline position. -
text-shadowAdds shadows to text. -
text-overflowControls clipped text rendering. -
text-wrapShorthand for text-wrap-mode and style. -
text-wrap-modeControls whether text wraps. -
text-wrap-styleBalance, pretty and stable wrapping. -
text-emphasisAdds emphasis marks. -
text-justifyControls justification. -
text-orientationSets glyph orientation in vertical text. -
text-renderingHints how to render text. -
text-boxShorthand for text-box-trim and text-box-edge. -
text-box-trimTrims half-leading from text boxes. -
text-box-edgeSets which font metrics define the text box edges. -
white-spaceControls whitespace handling. -
white-space-collapseControls whitespace collapsing. -
word-breakControls word breaking. -
line-breakControls line breaking rules. -
hyphensControls hyphenation. -
hyphenate-characterSets the hyphenation character. -
tab-sizeSets the tab width. -
directionSets text direction. -
unicode-bidiControls bidirectional text embedding. -
writing-modeSets horizontal or vertical writing. -
quotesSets quotation marks. -
initial-letterCreates drop caps. -
hanging-punctuationLets punctuation hang outside the box. -
vertical-alignAligns inline-level boxes. -
line-clampLimits text to a number of lines. -
caret-colorSets the text caret color.
Colors and Backgrounds
-
colorSets the text color. -
opacitySets element transparency. -
backgroundShorthand for background properties. -
background-colorSets the background color. -
background-imageSets background images. -
background-positionSets the background position. -
background-position-xSets the horizontal position. -
background-position-ySets the vertical position. -
background-repeatControls background tiling. -
background-sizeSets the background size. -
background-attachmentSets scroll behavior of backgrounds. -
background-originSets the positioning area. -
background-clipSets the painting area. -
background-blend-modeBlends background layers. -
color-schemeDeclares supported light and dark schemes. -
accent-colorColors form controls. -
forced-color-adjustOpts out of forced colors. -
print-color-adjustControls color adjustment when printing. -
mix-blend-modeBlends an element with what is behind it. -
color valuesColor notations: named, hex, rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), color().
Borders, Outlines and Shadows
-
borderShorthand for border width, style and color. -
border-widthSets border widths. -
border-styleSets border styles. -
border-colorSets border colors. -
border-topShorthand for the top border. -
border-rightShorthand for the right border. -
border-bottomShorthand for the bottom border. -
border-leftShorthand for the left border. -
border-radiusRounds the corners. -
border-top-left-radiusRounds the top-left corner. -
border-top-right-radiusRounds the top-right corner. -
border-bottom-left-radiusRounds the bottom-left corner. -
border-bottom-right-radiusRounds the bottom-right corner. -
border-imageShorthand for border images. -
border-image-sourceSets the border image. -
border-image-sliceSlices the border image. -
border-image-widthSets the border image width. -
border-image-outsetExtends the border image. -
border-image-repeatSets border image repeating. -
border-collapseCollapses table borders. -
border-spacingSets spacing between table cells. -
corner-shapeSets the shape of rounded corners (limited support). -
outlineShorthand for outline width, style and color. -
outline-colorSets the outline color. -
outline-styleSets the outline style. -
outline-widthSets the outline width. -
outline-offsetSets the outline offset. -
box-shadowAdds shadows to boxes.
Transforms, Transitions and Animations
-
transformApplies 2D and 3D transforms. -
transform-originSets the transform origin. -
transform-stylePreserves 3D for children. -
transform-boxSets the reference box for transforms. -
translateIndividual translate property. -
rotateIndividual rotate property. -
scaleIndividual scale property. -
perspectiveSets 3D perspective depth. -
perspective-originSets the vanishing point. -
backface-visibilityShows or hides the back of an element. -
transitionShorthand for transitions. -
transition-propertyChooses properties to transition. -
transition-durationSets transition duration. -
transition-timing-functionSets transition easing. -
transition-delaySets transition delay. -
transition-behaviorAllows discrete properties to transition. -
animationShorthand for animations. -
animation-nameNames the keyframes. -
animation-durationSets animation duration. -
animation-timing-functionSets animation easing. -
animation-delaySets animation delay. -
animation-iteration-countSets repeat count. -
animation-directionSets whether an animation plays forwards, backwards or alternates. -
animation-fill-modeSets which styles apply before an animation starts and after it ends. -
animation-play-statePauses or resumes a running CSS animation. -
animation-compositionSets how an animation combines with the element's other values. -
animation-timelineLinks an animation to a scroll or view timeline. -
animation-rangeSets the part of a timeline an animation runs over. -
scroll-timelineDefines a named scroll progress timeline. -
view-timelineDefines a named view progress timeline. -
timeline-scopeScopes named timelines so other elements can use them. -
will-changeHints to the browser which properties will change soon. -
offset-pathDefines a motion path for an element to follow. -
offset-distanceSets the position of an element along its motion path. -
offset-rotateSets the rotation of an element along its motion path. -
view-transition-nameNames an element for view transitions. -
view-transition-classGroups view transition elements.
Filters, Masks and Shapes
-
filterApplies graphical effects. -
backdrop-filterFilters what is behind an element. -
clip-pathClips an element to a shape. -
maskShorthand for mask properties. -
mask-imageSets a mask image. -
mask-modeSets alpha or luminance masking. -
mask-positionSets the mask position. -
mask-repeatSets mask repeating. -
mask-sizeSets the mask size. -
mask-compositeCombines mask layers. -
mask-borderUses an image as a mask border. -
shape-outsideWraps text around a shape. -
shape-marginAdds a margin to shape-outside. -
shape-image-thresholdSets the alpha threshold for shape images. -
object-fitFits replaced content in its box. -
object-positionPositions replaced content. -
image-renderingHints image scaling. -
image-orientationControls image orientation.
Lists, Tables and Generated Content
-
list-styleShorthand for list styles. -
list-style-typeSets the marker type. -
list-style-positionPlaces markers inside or outside. -
list-style-imageUses an image as the marker. -
counter-resetCreates or resets counters. -
counter-incrementIncrements counters. -
counter-setSets counter values. -
contentGenerates content for pseudo-elements. -
table-layoutChooses the table layout algorithm. -
caption-sidePlaces the table caption. -
empty-cellsShows or hides empty cells.
Scrolling, Interaction and UI
-
scroll-behaviorSets smooth or instant scrolling. -
scroll-marginSets snap and scrollIntoView margins. -
scroll-paddingSets the scrollport padding for snapping and anchors. -
scroll-snap-typeEnables scroll snapping. -
scroll-snap-alignSets snap alignment. -
scroll-snap-stopPrevents skipping snap points. -
scrollbar-colorColors scrollbars. -
scrollbar-widthSets scrollbar thickness. -
scrollbar-gutterReserves space for scrollbars. -
overscroll-behaviorControls scroll chaining and bounce. -
touch-actionControls touch gestures. -
cursorSets the mouse cursor. -
pointer-eventsControls pointer targeting. -
user-selectControls text selection. -
resizeLets users resize an element. -
appearanceControls native control styling. -
interactivityMakes subtrees inert (limited support). -
zoomScales an element (non-standard until recently).
Container Queries and Logical Properties
-
containerShorthand for container-name and container-type. -
container-nameNames a query container. -
container-typeMakes an element a query container. -
inline-sizeLogical width. -
block-sizeLogical height. -
min-inline-sizeLogical minimum width. -
max-inline-sizeLogical maximum width. -
min-block-sizeLogical minimum height. -
max-block-sizeLogical maximum height. -
margin-blockLogical block-axis margins. -
margin-inlineLogical inline-axis margins. -
padding-blockLogical block-axis padding. -
padding-inlineLogical inline-axis padding. -
border-blockLogical block-axis borders. -
border-inlineLogical inline-axis borders. -
border-start-start-radiusLogical corner radius. -
logical propertiesOverview of logical properties and values (concept page).
Custom Properties, Cascade and Global Keywords
-
--*Custom properties (CSS variables) and var(). -
allResets all properties. -
initialThe initial keyword. -
inheritThe inherit keyword. -
unsetThe unset keyword. -
revertRolls a property back to the style of the previous origin. -
revert-layerRolls a property back to the value from the previous cascade layer. -
!importantRaises a declaration's priority in the cascade. -
cascade and specificityHow the cascade, layers and specificity decide the winner. -
inheritanceWhich properties inherit and how to control it. -
shorthand propertiesHow shorthands expand into their longhand properties.
Functions
-
calc()Performs calculations. -
min()Picks the smallest value. -
max()Picks the largest value. -
clamp()Clamps a value between a minimum and maximum. -
var()Reads a custom property. -
env()Reads environment values such as safe areas. -
attr()Reads an attribute value. -
url()References a resource. -
rgb()Defines a color in sRGB. -
hsl()Defines a color by hue, saturation and lightness. -
hwb()Defines a color by hue, whiteness and blackness. -
lab()Defines a color in CIE Lab. -
lch()Defines a color in CIE LCH. -
oklab()Defines a color in Oklab. -
oklch()Defines a color in Oklch. -
color()Defines a color in a named color space. -
color-mix()Mixes two colors. -
light-dark()Picks a value by color scheme. -
linear-gradient()Creates a linear gradient. -
radial-gradient()Creates a radial gradient. -
conic-gradient()Creates a conic gradient. -
repeating-linear-gradient()Repeats a linear gradient. -
repeat()Repeats grid tracks. -
minmax()Sets a size range for grid tracks. -
fit-content()Clamps to content size. -
translate() and friendsTransform functions: translate, rotate, scale, skew, matrix, perspective. -
cubic-bezier()Defines a cubic Bézier easing. -
steps()Defines stepped easing. -
linear()Defines piecewise-linear easing. -
blur() and filter functionsFilter functions: blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, saturate, sepia. -
circle() and basic shapesBasic shapes: inset, circle, ellipse, polygon, path. -
image-set()Offers images by resolution. -
round(), mod(), rem()Stepped value functions. -
sin(), cos(), tan() and friendsTrigonometric functions. -
pow(), sqrt(), exp(), log()Exponential functions. -
abs() and sign()Sign-related functions. -
anchor()Positions relative to an anchor. -
counter() and counters()Displays counter values. -
symbols() and other rare functionsRarely used functions overview.
Units and Values
-
pxThe pixel unit. -
emRelative to the element's font size. -
remRelative to the root font size. -
%Percentage values. -
vw, vh, vmin, vmaxViewport units. -
dvh, svh, lvhDynamic, small and large viewport units. -
cqw, cqh, cqi, cqbContainer query units. -
ch, ex, cap, ic, lh, rlhFont-relative units. -
cm, mm, in, pt, pc, QAbsolute length units. -
deg, rad, grad, turnAngle units. -
s and msTime units. -
dpi, dpcm, dppx, xUnits that measure pixel density (dots per inch, centimeter or pixel). -
frA fraction of the free space in a grid container. -
auto, none, normalWhat the keywords auto, none and normal mean across properties. -
numbers and integersPlain numeric values: integers, decimals and unitless numbers. -
strings and identifiersQuoted text values and unquoted names. -
url valuesReferences to files and fragments with url(). -
custom identifiersAuthor-chosen names for animations, counters, grid areas and more. -
min-content, max-content, fit-contentSizes an element from its content: smallest, largest or in between. -
named colorsColor keywords such as tomato and navy, plus currentcolor and transparent. -
system colorsKeywords like Canvas and ButtonText that follow the user's theme. -
math functions overviewA map of calc(), min(), max(), clamp() and the newer math functions. -
value definition syntaxHow to read notation like [ <length> | auto ]{1,4} in specs and references.
Media Queries and Features
-
width and height featuresTests the size of the viewport in media queries. -
prefers-color-schemeDetects whether the user prefers a light or dark interface. -
prefers-reduced-motionDetects whether the user asked the system for less motion. -
prefers-contrastDetects whether the user asked for more or less contrast. -
prefers-reduced-dataDetects a data-saving request (limited support). -
orientationDetects portrait or landscape. -
hover and any-hoverDetects hover capability. -
pointer and any-pointerDetects pointer precision. -
resolutionDetects pixel density. -
aspect-ratio featureDetects viewport aspect ratio. -
display-modeDetects PWA display mode. -
forced-colorsDetects forced colors mode. -
print and screen typesMedia types. -
scriptingDetects script availability. -
range syntaxThe modern comparison syntax (width >= 600px). -
container featuresFeatures available in @container. -
scroll-state() queriesContainer scroll-state queries (limited support).
Properties for Special Contexts
-
SVG properties in CSSfill, stroke, stroke-width, and other SVG presentation properties. -
fillSets the SVG fill. -
strokeSets the SVG stroke. -
stroke-widthSets the SVG stroke width. -
stroke-dasharrayCreates dashed SVG strokes. -
stroke-dashoffsetOffsets the stroke dash pattern. -
paint-orderSets fill, stroke and marker paint order. -
ruby-positionPositions ruby annotations. -
ruby-alignAligns ruby annotations. -
text-combine-uprightCombines characters in vertical text. -
pageAssigns an element to a named page. -
sizeSets the page size (an @page descriptor). -
printing CSSPrint stylesheet techniques (concept page). -
speech propertiesAural CSS and speech properties status (concept page).
Practical Pages
-
reset and normalizePractical CSS resets and what they do (concept page). -
centering cheat sheetWays to center in CSS (concept page). -
vendor prefixes-webkit-, -moz-, -ms- and when you still need them (concept page). -
default browser stylesThe user-agent stylesheet defaults (concept page). -
stacking contextsHow stacking contexts form (concept page). -
choosing a layout methodFlexbox vs grid vs float vs positioning (concept page). -
deprecated and legacy CSSProperties and values to avoid (concept page).
Không có kết quả nào khớp với “”. Hãy thử tìm kiếm trên trang.
Không có kết quả nào khớp với “”. Hãy thử tìm kiếm trên trang.