Emmet: Climb-Up `^` and Multiplication `*`

The last lesson covered "descending" with > and "laying flat" with +. When your structure gets complex enough that "a sibling needs to go back up a level," those two alone hit a wall — that's when you need ^ to climb up one level. To create 5, 10, or more identical elements at once, use * to repeat.

1. What You'll Learn


2. A Front-End Developer's Real Story

(1) Pain Point: Multi-Level Nesting and Getting "Stuck Deep"

Alice is refactoring an e-commerce homepage, converting a flat layout into a semantic HTML5 three-section structure (header + main + footer). She uses last lesson's body>header+main+footer for the outermost layer, then descends inside header with >nav>ul>li*5>a. But after finishing the header section, a problem arises: footer should follow main as a sibling, but she finds footer ends up inside header — because > keeps pushing the context deeper and deeper, and + just appends at the latest level.

Worse, she needs to build a 6-row by 5-column product table. 6 rows with *6 is no problem, but each row needs 5 td cells repeated — hand-coding 30 td elements means either retyping or writing a long, hard-to-read tr>td*5*6. Alice wonders: if only * could nest inside * properly.

(2) How ^ and * Solve It

Emmet provides two complementary operators to solve both problems:

Climb-up ^: when you finish writing deep inside header and want to jump back to the body level to append footer, a ^ "climbs out" one level, returning to the parent's sibling position. Alice only needs to add a ^ at the end of the header subtree, then append main+footer:

TEXT 📖 Display only
body>header>nav>ul>li*5>a^^main+footer

^^ climbs two levels up from inside ul (first out of ul, then out of nav, back to header level), so +main+footer becomes siblings of header.

Multiplication *: Emmet's * can be placed after any element to repeat it N times — and * can nest > inside to form sub-structures. An entire table is one line:

TEXT 📖 Display only
table>(tr>td*5)*6

tr>td*5 is a "row pattern," wrapped with *6 to repeat the pattern 6 times. From 30 td elements to one abbreviation line — from 5 minutes to 8 seconds.

(3) Benefits

^ and * are the core combination for Emmet's "complex structure" handling. Climb-up lets you precisely control which level each element belongs to; multiplication lets you batch-generate repeated structures in one line. After this lesson, Alice combines body>header+main+footer with ^^^ for perfect level control and writes a 6x5 table with * in one line — from 12 minutes down to 25 seconds. Next lesson's grouping () will make these operators even more powerful when combined.


3. The Climb-Up Operator ^: Return to the Parent Level

^ means climb up — move the position of subsequent elements back from the current level to the parent level. It addresses a common scenario: you've finished a subtree deep inside a nested structure and want the next element to be a sibling of an "ancestor" rather than staying trapped at the current level.

Syntax Meaning
^ Climb up 1 level (back 1 context level)
^^^ Climb up 3 levels
^bq is equivalent to +bq at the parent level Climb up and immediately append an element

(1) Single Climb-Up Illustration

Abbreviation Fragment Shape Key Difference
div+div>p>span+em^bq bq is a sibling of p (inside the second div) ^ triggers the climb
div+div>p>span+em+bq bq is a sibling of span and em (inside p) Without ^, still in p level

Key Point: Climb-up is one of Emmet's most confusing operators for beginners. Its "previous context" refers to the parent node in the syntax tree, not "the last element I typed." In other words, in div>ul>li^p, the ^ makes p a sibling of ul (both inside div), not a sibling of li (inside li).


4. The Multiplication Operator *: Batch-Repeating Elements

*N means repeat — duplicate the preceding element N times. This is Emmet's core operator for handling repeated structures like "N list items," "N table rows," and "N cards."

Syntax Meaning
li*5 5 li elements
div.card*3 3 div.card (implicit div, lesson 3)
tr>td*6 1 tr containing 6 td
(tr>td*6)*5 5 tr, each containing 6 td (grouping, lesson 6)

Tip: N in *N must be a positive integer. *1 is valid (equivalent to no repeat) but is usually simplified to the singular form. *0 in Emmet expands to nothing (generates no elements).

(1) Multiplication Scope

* only applies to the immediately preceding element, following the "local context" rule. To repeat an entire nested subtree as a unit, you must use parentheses () for grouping (lesson 6):

Abbreviation Repeat Scope Incorrect Usage (trying to repeat as a whole without parentheses)
ul>li*3 3 li
ul>li*3>a 3 li, each containing 1 a
tr>td*5*6 Only 5 td; *6 repeats the tr as a whole (Emmet parses as 5 td total, tr repeated 6 times) For "6 rows x 5 columns" use (tr>td*5)*6

5. Hands-On Examples

The following 5 examples cover all core scenarios for ^ and * — from single climb-up to multi-level climb-up, from simple repetition to nested grouped repetition.

▶ Example: Single Climb-Up div+div>p>span+em^bq (Difficulty: ★★)

The problem left from last lesson: how to make bq a sibling of p. The answer is adding a ^.

Abbreviation:

HTML
div+div>p>span+em^bq

Expands to:

HTML
<div></div>
<div>
  <p><span></span><em></em></p>
  <blockquote></blockquote>
</div>

Output:

TEXT 📖 Display only
Parse: div+div creates two sibling divs, >p descends into the second div to place p, >span+em places two siblings inside p. Finally, ^ triggers a climb: from the p level up to the div level (p's parent), so bq becomes a sibling of p — both are children of the second div. Without ^, bq would end up inside p, sibling to span and em.

▶ Example: Multi-Level Climb-Up div+div>p>span+em^^^bq (Difficulty: ★★)

Three consecutive ^ climb all the way to the root level.

Abbreviation:

HTML
div+div>p>span+em^^^bq

Expands to:

HTML
<div></div>
<div>
  <p><span></span><em></em></p>
</div>
<blockquote></blockquote>

Output:

TEXT 📖 Display only
`^^^` climbs up three times: first from p to the second div, second from the second div to the root, third tries again from the root but there's no "higher level" (stays in place). So bq ends up as a sibling of the second div, a direct child of the root. Note: the root level has no explicit container (there's no outermost div), so bq appears alongside div. This "rootless abbreviation" gets auto-wrapped by `<body>` in browsers, but be aware of how level changes affect subsequent CSS selectors.

▶ Example: Multiplication ul>li*5 (Difficulty: ★)

The most basic "batch-generate 5 li elements."

Abbreviation:

HTML
ul>li*5

Expands to:

HTML
<ul>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>

Output:

TEXT 📖 Display only
5 empty li elements, all direct children of ul. `*5` acts directly on li — no complex structure needed. This is Emmet's highest-frequency pattern for "5-item navigation menu," "5-item to-do list," "5 feature cards," and similar scenarios. Pair with content filling (lesson 9) to give each item different text.

▶ Example: Repeat + Nest ul>li*3>a (Difficulty: ★)

The classic > + * combo — a as the sole child of each li.

Abbreviation:

HTML
ul>li*3>a

Expands to:

HTML
<ul>
  <li><a href=""></a></li>
  <li><a href=""></a></li>
  <li><a href=""></a></li>
</ul>

Output:

TEXT 📖 Display only
`*3` only repeats li, and each li contains one a via >. To repeat a as well (3 a per li), use parentheses: ul>li*>a*3 or wrap a in a group. To repeat "(li and a)" as a unit, use (li>a)*3 (lesson 6, grouping). This is a classic Emmet "scope" gotcha.

This lesson's combined example: nested multiplication + grouping (() is from lesson 6 — previewed here).

Abbreviation:

HTML
(div>dl>(dt+dd)*3)+footer>p

Expands to:

HTML
<div>
  <dl>
    <dt></dt>
    <dd></dd>
    <dt></dt>
    <dd></dd>
    <dt></dt>
    <dd></dd>
  </dl>
</div>
<footer>
  <p></p>
</footer>

Output:

TEXT 📖 Display only
Parse: the outermost (div>dl>...) acts as a group, serving as a "virtual root." Inside the group, div contains dl, and (dt+dd)*3 inside dl repeats the dt+dd sibling pair 3 times. Then + makes footer a sibling of div (footer is a separate, independent subtree), and >p inside footer places a p. The entire abbreviation line expands to 13 lines of HTML: 1 dl, 6 dt/dd, 1 footer, 1 p. This is Emmet's typical pattern for writing a definition list block in one line.

6. Full Example: 6x5 Product Table

Use nested * and grouping to build a 6-row, 5-column product table with a single abbreviation line.

▶ Example: 6x5 Product Table (Difficulty: ★★)

Abbreviation:

HTML
table>(tr>td*5)*6

Expands to:

HTML
<table>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

Output:

TEXT 📖 Display only
Parse: tr>td*5 is the "one row of cells" template, and the outer *6 repeats this template 6 times. The parentheses (tr>td*5) ensure that td*5 only applies inside tr (5 td all in the same tr), rather than being directly repeated by the outer *6. Two nested * operators form a 2D grid. Without parentheses, tr>td*5*6 would still produce a 6x5 result (Emmet parses it as 5 td per tr, tr repeated 6 times), but the semantics are unclear — not recommended.

❓ FAQ

Q Before the ^ operator existed, how did people handle climb-up needs?
A Early Emmet versions indeed had no climb-up operator. You had to use "grouping + re-descend" to simulate climbing. For example, div>header>p+span^(main+footer) didn't exist; you'd write (header>p+span)+(main+footer) using grouping as a workaround. But grouping is less readable and requires re-descending. ^ was added in 2013 as an "escape hatch" specifically to solve this pain point.
Q Can ^ climb all the way to the root? What happens if you climb too far?
A Yes, you can keep climbing, but only up to the root (virtual root). Climbing past the root (e.g., ^^^^^bq at the root level) just stays at the root — no error. Emmet treats the root as the "bottom floor," and excess ^ symbols are silently ignored.
Q What does li*0 expand to?
A *0 in the official Emmet generates 0 elements (completely skipped), but some editor implementations may leave a single empty li element. Avoid writing *0 — just write li explicitly. If you expect "0 elements" and your editor gives you 1 empty one, that's an editor implementation difference.
Q In div>span*3>p, where does the p end up?
A It expands to <div><span><p></p></span><span><p></p></span><span><p></p></span></div> — p is a child of each span (because the nearest context is span). *3 only repeats span, and p follows each span. This is one of the most confusing patterns for beginners: distinguishing the scope of * (only the immediately preceding element) from the scope of subsequent > (the nearest context).

📖 Summary


📝 Exercises

  1. Basic (Difficulty: ★): Write 3 Emmet abbreviations using * that expand to: (a) 5 li; (b) 1 ul containing 3 li, each li containing 1 a; (c) 1 ul containing 1 li, the li containing 3 a.
  2. Intermediate (Difficulty: ★★): Analyze how (nav>ul>li*3>a)+main+footer should expand (sketch it on paper first, then verify by expanding). Then rewrite it as an equivalent version using ^ (without parentheses).
  3. Challenge (Difficulty: ★★★): Write a single Emmet abbreviation for an 8x8 chessboard table (first cell is <th> heading, the rest are <td>). Explain why this structure requires parentheses for grouping. Also write the "wrong version" without parentheses and compare the actual expansion results.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏