Skip to content
Related Articles

Related Articles

CSS | attr() Function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 07 Mar, 2022

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

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:


<!DOCTYPE html>
        <title>attr function</title>
            a:before {
                content: attr(href) " =>";
            a {
            .gfg {
            body {
        <div class = "gfg">GeeksforGeeks</div>
        <h1>The attr() Function</h1>
        <a href="">GeeksforGeeks</a>


Supported Browser:

  • Google Chrome 2.0
  • Internet Explorer 8.0
  • Firefox 1.0
  • Opera 9.0
  • Safari 3.1

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!