The Wayback Machine - https://web.archive.org/web/20230512160215/https://www.geeksforgeeks.org/css-attr-function/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

CSS | attr() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The attr() function is an inbuilt function in CSS which returns the value of an attribute of the selected elements.

Syntax: 

attr( attr_name )

Parameter: This function accepts single parameter attr_name which is used to hold the name of attribute in HTML element. It is mandatory parameter.

Return Value: This function returns the value of attribute of selected elements.

Below example illustrates the attr() function in CSS:

Program: 

html




<!DOCTYPE html>
<html>
    <head>
        <title>attr function</title>
        <style>
            a:before {
                content: attr(href) " =>";
            }
            a {
                text-decoration:none;
            }
            .gfg {
                font-size:40px;
                color:green;
                font-weight:bold;
            }
            body {
                text-align:center;
            }
        </style>
    </head>
    <body>
        <div class = "gfg">GeeksforGeeks</div>
        <h1>The attr() Function</h1>
        <a href="https://www.geeksforgeeks.org">GeeksforGeeks</a>
    </body>
</html>

Output: 

Supported Browser:

  • Google Chrome 2.0
  • Edge 12
  • Internet Explorer 8.0
  • Firefox 1.0
  • Opera 9.0
  • Safari 3.1 
My Personal Notes arrow_drop_up
Last Updated : 01 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials