Open In App

What does the “+” (plus sign) CSS selector mean?

Last Updated : 30 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The “+” (plus sign) CSS selector, known as the adjacent sibling selector, targets the first element that immediately follows another specified element in the HTML structure. It applies styles only to the directly adjacent sibling after the selected element.

Note: The IE8 and earlier versions </DOCTYPE> must be declared to work element + element selector.

Syntax:

element + element {
    // CSS property
} 

Example: In this example, we demonstrate the use of the adjacent sibling (+) CSS selector, targeting the <div> immediately following the <h2> element, applying styling like font size, color, and background color.

html
<!DOCTYPE html>
<html>

<head>
    <title>+ sign selector</title>
    <style>
        h2+div {
            font-size: 20px;
            font-weight: bold;
            display: inline;
            background-color: yellow;
            color: green;
        }

        h1 {
            color: green;
        }

        body {
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>+ sign Selector</h2>
    <div>A computer science portal for geeks</div>
</body>

</html>

Output:

Supported Browsers:

The browser supported by “+” selector are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer 7.0

Next Article

Similar Reads

three90RightbarBannerImg
  翻译: