function
attr() — CSS reference
Reads an attribute from the element on which the value is computed. Traditional attr() supplies a string for generated content; typed attr() parses a number with a unit or a supported type. Missing or unparsable typed input uses fallback. A present empty raw string is still present. Attribute-tainted values cannot be used to construct URLs. Check support before using typed forms.
Formal Syntax & Structure
css syntaxcss
attr(data-label); attr(data-size px, 40px); attr(data-size type(<length>), 40px);Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS substitution lab</title><style>body {margin:0} .sample {height:12px;background:#006050}#parent {width:300px} .sample {width:40px;height:30px;margin-bottom:4px;color:white}#a{width:attr(data-size px,40px)} #b{width:attr(data-size px,40px)} #a::before{content:attr(data-label)}</style><body><div id="parent"><div id="a" data-size="65" data-label="Ready" class="sample">A</div><div id="b" data-size="wrong" class="sample">B</div></div></body></html>