Open In App
Related Articles

CSS attr() Function

Improve Article
Save Article
Like Article

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


attr( attr_name )

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

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

Example: The below example illustrates the attr() function in CSS:


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


Supported Browser:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari  

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 04 Aug, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials