CSS Attribute Selector

## CSS Basic

CSS HOME CSS Introduction CSS Syntax CSS Id & Class CSS How To CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS Tables

## CSS Box Model

CSS Box Model CSS Border CSS Outline CSS Margin CSS Padding

## CSS Advanced

CSS Grouping/Nesting CSS Dimension CSS Display CSS Positioning CSS Floating CSS Align CSS Pseudo-class CSS Pseudo-element CSS Navigation Bar CSS Image Gallery CSS Image Opacity CSS Image Sprites CSS Media Types CSS Attr Selectors

## CSS3 Tutorial

CSS3 Introduction CSS3 Borders CSS3 Backgrounds CSS3 Gradients CSS3 Text Effects CSS3 Fonts CSS3 2D Transforms CSS3 3D Transforms CSS3 Transitions CSS3 Animations CSS3 Multiple Columns CSS3 User Interface CSS Summary

## CSS Examples

CSS Examples CSS Quiz CSS Certificate

## CSS References

CSS Reference CSS Selectors CSS Reference Aural CSS Web Safe Fonts CSS Units CSS Colors CSS Color Values CSS Color Names CSS Color HEX

# CSS Attribute Selectors

« Previous
Next Chapter »

## Style HTML Elements With Specific Attributes

It is possible to style HTML elements that have specific attributes, not just class and id.

| Note: IE7 and IE8 support attribute selectors only if a !DOCTYPE is specified.

## Attribute Selector

The example below styles all elements with a title attribute:

## Example

[title]
{
color:blue;
}
Try it yourself »

## Attribute and Value Selector

The example below styles all elements with title="W3Schools":

## Example

[title=W3Schools]
{
border:5px solid green;
}
Try it yourself »

## Attribute and Value Selector - Multiple Values

The example below styles all elements with a title attribute that contains a specified value. This works even if the attribute has space separated values:

## Example

[title~=hello] { color:blue; }
Try it yourself »

The example below styles all elements with a lang attribute that begins with a specified value:

## Example

[lang|=en] { color:blue; }
Try it yourself »

## Styling Forms

The attribute selectors are particularly useful for styling forms without class or ID:

## Example

input[type="text"]
{
width:150px;
display:block;
margin-bottom:10px;
background-color:yellow;
}
input[type="button"]
{
width:120px;
margin-left:35px;
display:block;
}
Try it yourself »
« Previous
Next Chapter »

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE