-
Notifications
You must be signed in to change notification settings - Fork 23k
40483 heading selectors #40649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
40483 heading selectors #40649
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c3ebe9a
added the :heading and :heading pages
dletorey c06d7bc
Merge branch 'main' into 40483-heading-selectors
dletorey dd69d01
finshed the :heading & :heading() pages
dletorey 169f663
added note to :heading() and added both to pseudo-classes page
dletorey af829de
Merge branch 'main' into 40483-heading-selectors
dletorey 10ceb0a
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey e96bf2a
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 984b927
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 917d7f8
made explanation match code example
dletorey 531fb9f
Update files/en-us/web/css/_colon_heading/index.md
dletorey 77ac648
Update files/en-us/web/css/_colon_heading/index.md
dletorey 0630303
Update files/en-us/web/css/_colon_heading/index.md
dletorey d2d981e
Update files/en-us/web/css/_colon_heading/index.md
dletorey a862da4
Update files/en-us/web/css/_colon_heading/index.md
dletorey 396f6b5
Update files/en-us/web/css/_colon_heading/index.md
dletorey 70af4d7
Update files/en-us/web/css/_colon_heading/index.md
dletorey 2b93476
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 1030607
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey f258db7
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey d587432
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 96c21f7
Update files/en-us/web/css/_colon_heading/index.md
dletorey 2667e9e
Merge branch 'main' into 40483-heading-selectors
dletorey 1248fc1
fixed code blocks
dletorey faa1fc0
Merge branch 'main' into 40483-heading-selectors
dletorey ba72433
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 1cb2752
updated the Note & parameters
dletorey 9944d0c
Merge branch '40483-heading-selectors' of github.com:dletorey/content…
dletorey 0c962f8
fixed the syntax example
dletorey 1ef85b8
added a note about matching attributes
dletorey 8070f80
moved the note to usage notes
dletorey bf5bdc8
Merge branch 'main' into 40483-heading-selectors
dletorey a7d3ed4
Merge branch 'main' into 40483-heading-selectors
dletorey 714d935
Merge branch 'main' into 40483-heading-selectors
caugner c5f8d28
Update files/en-us/web/css/_colon_heading/index.md
dletorey 0979834
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 0ed3a0f
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey a2bce13
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 1587bc1
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 6104a30
Update files/en-us/web/css/_colon_heading_function/index.md
dletorey 509583b
Merge branch 'main' into 40483-heading-selectors
dletorey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| title: :heading | ||
| slug: Web/CSS/:heading | ||
| page-type: css-pseudo-class | ||
| browser-compat: css.selectors.heading | ||
| sidebar: cssref | ||
| --- | ||
|
|
||
| The **`:heading`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches all [heading elements](/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements) in a document. This allows you to style all headings at once, rather than matching and styling them individually. | ||
| This pseudo-class matches only elements that are semantically recognized as headings (`<h1>` through `<h6>`). Elements with [`role="heading"`](/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/heading_role) are not matched; you can select those by using the functional form, {{CSSXRef(":heading_function", ":heading()")}}. | ||
|
|
||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > [!NOTE] | ||
| > The `:heading` pseudo-class has the same [specificity](/en-US/docs/Web/CSS/CSS_cascade/Specificity#how_is_specificity_calculated) as a class selector, that is, `0-1-0`. So `:heading` would have a specificity of `0-1-0`, and `section:heading` would have a specificity of `0-1-1`. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```css | ||
| :heading { | ||
| /* ... */ | ||
| } | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Styling all headings | ||
|
|
||
| The document in this example contains headings at three different levels. | ||
|
|
||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ```html | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <h1>Mastering CSS</h1> | ||
| <h2>Chapter 1: Selectors</h2> | ||
| <h3>1.1 Pseudo-classes</h3> | ||
| ``` | ||
|
|
||
| ```css | ||
| :heading { | ||
| color: tomato; | ||
| } | ||
| ``` | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| The `:heading` pseudo-class applies the `color` to all the headings in the document: | ||
|
|
||
| {{EmbedLiveSample("styling_all_headings", "", "170")}} | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The `:heading` pseudo-class applies the `color` to all the headings in the document. | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - {{CSSXRef(":heading_function", ":heading()")}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| --- | ||
| title: :heading() | ||
| slug: Web/CSS/:heading_function | ||
| page-type: css-pseudo-class | ||
| browser-compat: css.selectors.headingfunction | ||
| sidebar: cssref | ||
| --- | ||
|
|
||
| The **`:heading()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) function represents all [heading elements](/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements) that match a value calculated using the `An+B` notation. This allows you to style elements at specific heading levels at once, rather than matching and styling them individually. | ||
|
|
||
| > [!NOTE] | ||
| > The `:heading()` functional pseudo-class has the same [specificity](/en-US/docs/Web/CSS/CSS_cascade/Specificity#how_is_specificity_calculated) as a class selector, that is, `0-1-0`. So `:heading()` would have a specificity of `0-1-0`, and `section:heading()` would have a specificity of `0-1-1`. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```css-nolint | ||
| :heading([ <An+B> [, <An+B>]* | even | odd ]) { | ||
| /* ... */ | ||
| } | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| The `:heading()` pseudo-class function takes a comma-separated list of `An+B` expressions or keyword values that describe a pattern for matching heading elements. | ||
|
|
||
| #### Keyword values | ||
|
|
||
| - `odd` | ||
| - : Represents the heading elements whose numeric position is odd: `<h1>`, `<h3>`, and `<h5>`. | ||
| - `even` | ||
| - : Represents the heading elements whose numeric position is even: `<h2>`, `<h4>`, and `<h6>`. | ||
|
|
||
| #### Functional notation | ||
|
|
||
| - `<An+B>` | ||
| - : Represents the heading elements whose numeric position matches the pattern `An+B`, for every positive integer or zero value of `n`, where: | ||
| - `A` is an integer step size, | ||
| - `B` is an integer offset, | ||
| - `n` is all nonnegative integers, starting from 0. | ||
|
|
||
| It can be read as the `An+B`-th element of a list. The `A` and `B` must both have {{cssxref("<integer>")}} values. | ||
|
|
||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Usage notes | ||
|
|
||
| The `:heading()` functional pseudo-class matches only elements that are semantically recognized as headings. It does not match elements with a [`role="heading"`](/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/heading_role) attribute, nor does it respect the ['aria-level'](/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-level) ARIA attribute. | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Examples | ||
|
|
||
| ### Using keyword parameters | ||
|
|
||
| In this example, the `odd` keyword matches headings with odd-numbered levels, which are `<h1>` and `<h3>`. The `even` keyword is used to target even-numbered heading levels, `<h2>` and `<h4>`. | ||
|
|
||
| ```html | ||
| <h1>Heading 1</h1> | ||
| <h2>Heading 2</h2> | ||
| <h3>Heading 3</h3> | ||
| <h4>Heading 4</h4> | ||
| ``` | ||
dletorey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```css | ||
| :heading(odd) { | ||
| color: tomato; | ||
| } | ||
| :heading(even) { | ||
| color: slateblue; | ||
| } | ||
| ``` | ||
|
|
||
| {{EmbedLiveSample("Keyword_example", "", "215")}} | ||
|
|
||
| ### Using the `An+B` notation | ||
|
|
||
| ```html | ||
| <h1>Science</h1> | ||
| <h2>Physics</h2> | ||
| <h3>Atomic, molecular, and optical physics</h3> | ||
| <h4>Optical physics</h4> | ||
| <h5>X-Rays</h5> | ||
| <h6>Discovery</h6> | ||
| ``` | ||
|
|
||
| ```css hidden | ||
| main { | ||
| display: flex; | ||
| justify-content: space-around; | ||
| } | ||
| ``` | ||
|
|
||
| ```css | ||
| /* Targets headings <h3> and <h4> */ | ||
| :heading(3, 4) { | ||
| font-weight: 100; | ||
| } | ||
| /* Targets headings in reverse starting from <h3> */ | ||
| :heading(-n + 3) { | ||
| color: tomato; | ||
| } | ||
| /* Targets every third heading starting from <h1> */ | ||
| :heading(3n + 1) { | ||
| font-style: italic; | ||
| } | ||
| /* Targets headings after level 5 */ | ||
| :heading(n + 5) { | ||
| color: slateblue; | ||
| } | ||
|
|
||
| In this example: | ||
| - `:heading(3, 4)` matches the `<h3>` and `<h4>` elements | ||
| - `:heading(-n + 3)` matches heading elements in reverse, so `<h3>`, `<h2>`, and `<h1>` | ||
| - `:heading(3n + 1)` matches every third (`3n`) heading element starting from `<h1>`, so this would include `<h1>` and `<h4>` | ||
| - `:heading(n + 5)` matches heading elements starting from `<h5>` and will include `<h6>` | ||
|
|
||
| {{EmbedLiveSample("Functional_notation_example", "", "292")}} | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - {{CSSXRef(":heading")}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.