VOOZH about

URL: https://www.geeksforgeeks.org/css/css-attr-function/

⇱ CSS attr() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS attr() Function

Last Updated : 11 Jul, 2025

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

Syntax:

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:

Output:

👁 Image

Supported Browser:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari  
Comment