CSS hanging-punctuation Property

The CSS hanging-punctuation property controls whether certain punctuation marks can extend outside the start or end edges of a text line.

This typographic technique, known as hanging punctuation, helps create visually consistent text alignment. It is especially useful for quotation marks, punctuation at line endings, and text containing East Asian punctuation characters. Browser support is limited, so the effect may not appear consistently across browsers.

hanging-punctuation Syntax

The hanging-punctuation property accepts none or a combination of keywords that control punctuation at the beginning and end of text lines.

Basic Syntax

selector {
  hanging-punctuation: none;
}

Hang Punctuation at the Beginning

blockquote {
  hanging-punctuation: first;
}

Hang Punctuation at the End of the Last Line

blockquote {
  hanging-punctuation: last;
}

Allow Punctuation to Hang at Line Endings

p {
  hanging-punctuation: allow-end;
}

Force Punctuation to Hang at Line Endings

p {
  hanging-punctuation: force-end;
}

Combine Beginning and Ending Behavior

blockquote {
  hanging-punctuation: first last;
}

Combine Multiple Keywords

p {
  hanging-punctuation: first force-end last;
}

CSS-Wide Keywords

p {
  hanging-punctuation: initial;
}
p {
  hanging-punctuation: inherit;
}
p {
  hanging-punctuation: unset;
}
p {
  hanging-punctuation: revert;
}
p {
  hanging-punctuation: revert-layer;
}

The allow-end and force-end keywords are alternatives and cannot appear together in the same declaration. The first and last keywords can be combined with either ending behavior.

Property Values

The property uses four primary keywords to control which punctuation marks may hang outside a line's normal content boundaries.

Value Description
none Disables hanging punctuation.
first Allows eligible opening punctuation at the beginning of the first formatted line to hang.
last Allows eligible closing punctuation at the end of the last formatted line to hang.
allow-end Allows eligible punctuation at the end of a line to hang when it would otherwise not fit before the line break.
force-end Forces eligible punctuation at the end of a line to hang rather than occupying its normal space within the line.
initial Resets the property to none.
inherit Inherits the computed value from the parent element.
unset Inherits the parent's value because this property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited Yes
Applies to Block containers
Computed value As specified
Animation type Discrete
Percentages Not applicable
Related properties text-align, text-indent, text-justify, white-space

Hanging punctuation affects the visual positioning of eligible characters. It does not insert, remove, or replace punctuation in the document.

How It Works

Normally, punctuation occupies space inside the line box along with letters and other characters. Hanging punctuation permits certain marks to extend beyond the normal text edge.

Normal Punctuation Placement

blockquote {
  hanging-punctuation: none;
}

Opening quotation marks remain inside the text alignment boundary.

Hanging Punctuation Placement

blockquote {
  hanging-punctuation: first;
}

When supported, an eligible opening quotation mark can extend outside the start edge of the first line, allowing the following text to align more closely with other lines.

Line-End Punctuation

p {
  hanging-punctuation: force-end;
}

Eligible punctuation at a line ending can extend beyond the normal end edge instead of taking up its usual space within the line.

Important Consideration

The exact visual result depends on the punctuation character, font metrics, writing direction, line-breaking rules, and browser implementation. Not every punctuation character is eligible to hang.

The first Value

The first keyword controls eligible punctuation at the beginning of the first formatted line of a block.

Opening Quotation Mark

blockquote {
  hanging-punctuation: first;
}

HTML Example

<blockquote>
  <p>“CSS Grid makes complex layouts easier to organize.”</p>
</blockquote>

When supported and applied to the block containing the text, the opening quotation mark can extend into the margin rather than shifting the following text inward.

Apply to a Specific Paragraph

.featured-quote {
  hanging-punctuation: first;
}

Important Consideration

The first keyword does not apply hanging behavior to every quotation mark in the paragraph. It concerns eligible punctuation at the start of the first formatted line.

For a quotation inside a nested paragraph, applying the property directly to that paragraph is generally clearer than relying on inheritance from a surrounding element.

The last Value

The last keyword controls eligible punctuation at the end of the last formatted line of a block.

Closing Quotation Mark

blockquote p {
  hanging-punctuation: last;
}

Combine Opening and Closing Behavior

blockquote p {
  hanging-punctuation: first last;
}

This combination allows eligible punctuation at both the beginning of the first line and the end of the last line to hang.

Example Text

<p class="quotation">
  “Well-structured CSS is easier to maintain.”
</p>

CSS Example

.quotation {
  hanging-punctuation: first last;
}

Important Consideration

The last keyword concerns the final formatted line. It does not force punctuation on earlier line endings to hang.

The allow-end Value

The allow-end keyword permits eligible punctuation at a line ending to hang when doing so avoids moving that punctuation to the next line.

Allow Hanging at Line Endings

.article-text {
  hanging-punctuation: allow-end;
}

The browser may position eligible punctuation outside the line's normal end edge when it would otherwise exceed the available line width.

Use with Constrained Text Width

.article-text {
  max-width: 30rem;
  hanging-punctuation: allow-end;
}

A constrained text width can make line breaks easier to observe, although the exact result still depends on the text and browser.

Important Consideration

The allow-end value is conditional. It does not require every eligible punctuation mark at a line ending to hang.

This value is particularly relevant to East Asian text, where punctuation and line-breaking conventions differ from those commonly used in English.

The force-end Value

The force-end keyword requires eligible punctuation at a line ending to hang, rather than leaving it inside the normal line boundary.

Force Hanging at Line Endings

.article-text {
  hanging-punctuation: force-end;
}

Combine with First-Line Punctuation

.article-text {
  hanging-punctuation: first force-end;
}

Combine with Final-Line Punctuation

.article-text {
  hanging-punctuation: force-end last;
}

Compare with allow-end

Value Behavior
allow-end Allows eligible punctuation to hang when necessary to avoid a line break.
force-end Requires eligible punctuation at the applicable line ending to hang.

Important Consideration

The word force does not mean every punctuation character must hang. The behavior applies only to characters covered by the relevant punctuation and line-breaking rules.

Combining Values

The property can combine keywords to control punctuation at different positions in the same text block.

First and Last

.quotation {
  hanging-punctuation: first last;
}

Allows eligible punctuation to hang at the beginning of the first line and at the end of the last line.

First and allow-end

.article-text {
  hanging-punctuation: first allow-end;
}

First and force-end

.article-text {
  hanging-punctuation: first force-end;
}

All Applicable Positions

.article-text {
  hanging-punctuation: first force-end last;
}

Invalid Combination

.article-text {
  hanging-punctuation: allow-end force-end;
}

This declaration is invalid because allow-end and force-end are mutually exclusive.

Important Consideration

Each keyword may appear at most once in a declaration. The none keyword must be used by itself.

Punctuation and Writing Systems

Hanging punctuation is influenced by the writing system and the Unicode characteristics of punctuation marks.

Quotation Marks

Opening and closing quotation marks can be candidates for hanging at the beginning or end of text, depending on their character classifications and position.

East Asian Punctuation

East Asian typography uses punctuation conventions that may place marks at line boundaries differently from English text. The allow-end and force-end values are designed for eligible punctuation at these boundaries.

Japanese Text Example

<p lang="ja" class="japanese-text">
  「CSSはウェブページの表示を制御します。」
</p>

CSS Example

.japanese-text {
  hanging-punctuation: first force-end last;
}

Writing Direction

.quotation {
  direction: rtl;
  hanging-punctuation: first last;
}

Line start and line end follow the text's writing direction. They are not always equivalent to the physical left and right edges.

Important Consideration

Hanging punctuation does not automatically translate punctuation characters or change the language of the content. Use appropriate HTML language attributes and valid text encoding.

Text Alignment

Hanging punctuation is a typographic refinement that can complement text alignment, but it does not replace alignment properties.

Left-Aligned Text

.quotation {
  text-align: left;
  hanging-punctuation: first;
}

Start-Aligned Text

.quotation {
  text-align: start;
  hanging-punctuation: first last;
}

The start value respects the writing direction, making it useful for multilingual content.

Justified Text

.article-text {
  text-align: justify;
  hanging-punctuation: allow-end;
}

Hanging punctuation can affect line-edge typography independently of the spacing adjustments performed by justification.

Text Indentation

.article-text {
  text-indent: 2rem;
  hanging-punctuation: first;
}

The text-indent property changes the indentation of the first line, while hanging-punctuation controls eligible punctuation at line boundaries.

Important Consideration

Hanging punctuation is not the same as a hanging indent. For hanging indents, use text-indent with an appropriate negative value and matching padding or margin.

Inheritance

The hanging-punctuation property is inherited. Descendant elements receive the parent's computed value unless they specify another value.

Apply to a Parent

article {
  hanging-punctuation: first last;
}

Override a Descendant

article .plain-text {
  hanging-punctuation: none;
}

Explicit Inheritance

blockquote {
  hanging-punctuation: inherit;
}

Reset to the Initial Value

blockquote {
  hanging-punctuation: initial;
}

Use unset

blockquote {
  hanging-punctuation: unset;
}

Because the property is inherited, unset behaves like inherit rather than resetting to none.

Important Consideration

For predictable results, apply the property directly to the block containing the text whose punctuation should hang.

hanging-punctuation Example

This example compares normal punctuation placement with a paragraph using hanging-punctuation: first last. In supporting browsers, the quotation marks may extend beyond the normal text edges.

HTML Example

<div class="hanging-punctuation-demo">
  <div class="demo-panel">
    <h3>Normal Punctuation</h3>
    <p class="normal-quote">“Good CSS makes web layouts easier to maintain.”</p>
  </div>
  <div class="demo-panel">
    <h3>Hanging Punctuation</h3>
    <p class="hanging-quote">“Good CSS makes web layouts easier to maintain.”</p>
  </div>
</div>

CSS Example

.hanging-punctuation-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.hanging-punctuation-demo .demo-panel {
  padding: 15px;
  border: 1px solid #cccccc;
  border-radius: 4px;
  min-width: 0;
}
.hanging-punctuation-demo h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.hanging-punctuation-demo p {
  margin: 0;
  line-height: 1.6;
  overflow-wrap: break-word;
}
.hanging-punctuation-demo .normal-quote {
  hanging-punctuation: none;
}
.hanging-punctuation-demo .hanging-quote {
  hanging-punctuation: first last;
}
@media (max-width: 575px) {
  .hanging-punctuation-demo {
    grid-template-columns: 1fr;
  }
}
Browser Result

Normal Punctuation

“Good CSS makes web layouts easier to maintain.”

Hanging Punctuation

“Good CSS makes web layouts easier to maintain.”

In browsers that support the relevant values, the opening quotation mark in the second paragraph may hang outside the start edge. The closing quotation mark may hang at the end of the last line.

If both paragraphs look identical, the browser may not support the property or the particular punctuation behavior. The text remains readable without hanging punctuation.

Try force-end

.hanging-punctuation-demo .hanging-quote {
  hanging-punctuation: first force-end last;
}

This variation adds forced hanging behavior for eligible punctuation at applicable line endings. The result depends on the text and browser support.

Common Mistakes

Expecting Universal Browser Support

Support for hanging-punctuation is limited. A browser may ignore the property or support only certain values.

Using Invalid Keywords

p {
  hanging-punctuation: left right;
}

The property does not accept left or right. Use the defined punctuation-position keywords.

Combining Mutually Exclusive Values

p {
  hanging-punctuation: allow-end force-end;
}

The allow-end and force-end values cannot be used together.

Combining none with Other Values

p {
  hanging-punctuation: none first;
}

The none keyword must appear alone.

Assuming Every Punctuation Mark Can Hang

The property applies to specific punctuation categories and positions. Ordinary punctuation elsewhere in a line is not automatically moved.

Confusing Hanging Punctuation with Hanging Indentation

Hanging punctuation affects eligible punctuation marks at line boundaries. A hanging indent is a separate paragraph formatting technique controlled by properties such as text-indent.

Expecting the Property to Change the Text

The property changes visual placement only. It does not modify the punctuation characters in the HTML source.

Assuming allow-end Always Hangs Punctuation

The allow-end value permits hanging under specific line-breaking conditions. Use force-end when forced hanging is required for eligible line-end punctuation.

Important Considerations

Keep the following points in mind when using hanging-punctuation:

  • The property controls eligible punctuation at the start and end edges of text lines.
  • The initial value is none.
  • The property is inherited.
  • The first keyword controls eligible punctuation at the beginning of the first formatted line.
  • The last keyword controls eligible punctuation at the end of the last formatted line.
  • The allow-end keyword permits hanging under applicable line-breaking conditions.
  • The force-end keyword requires eligible line-end punctuation to hang.
  • The allow-end and force-end values cannot be combined.
  • The none keyword must appear alone.
  • Writing direction and punctuation character classification affect the result.
  • The property does not replace text-align or text-indent.
  • Browser support is limited and may differ by keyword.
  • Unsupported declarations are ignored, leaving punctuation in its normal layout position.
  • Use hanging punctuation as a progressive enhancement rather than a requirement for readable content.

Browser Support

The CSS hanging-punctuation property has limited availability across browsers. Support varies by browser and by individual keyword, so it should not be treated as a universally supported CSS feature.

For current compatibility information, visit Can I Use? and search for hanging-punctuation.

When a browser does not recognize the declaration, it ignores the property and uses normal punctuation positioning. Keep text layouts readable without relying on hanging punctuation.

Specifications

The hanging-punctuation property is defined in the CSS Text Module Level 3 specification.

CSS Text Module Level 3: hanging-punctuation

The specification describes the eligible punctuation categories and the behavior of punctuation at the beginning and end of formatted lines.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: hanging-punctuation