dev.rean.me
css

VS Code CSS Shorthand (Emmet) — Complete Guide with Tips

Master VS Code Emmet abbreviations for CSS to write stylesheets 10x faster. Learn CSS shorthand syntax, cheat sheet, flexbox/grid shortcuts, and pro tips.

2026-09-11 · 9 min read

Share:

VS Code CSS Shorthand with Emmet — Write CSS 10× Faster!

Hello friend! Writing CSS manually property by property (like typing display: flex; justify-content: center; align-items: center;) takes a lot of time and keystrokes.

Did you know VS Code has built-in Emmet for CSS? You can type short abbreviations like df + Tab, jcc + Tab, and aic + Tab to generate full CSS declarations instantly!

In this guide, we will learn all essential CSS Emmet shorthands, unit tricks, flexbox/grid abbreviations, cheat sheet, and pro tips in VS Code.

💡 Emmet is built into VS Code out of the box — no extra plugin required!

If you want to explore more CSS and HTML guides:


How CSS Emmet Works in VS Code

In CSS, Emmet uses property initials + values.

When you type an abbreviation in a .css, .scss, .less, or <style> block and press Tab or Enter, VS Code expands it automatically.

Key Rules of CSS Emmet:

  1. Property initials: d → display: ;, m → margin: ;, p → padding: ;, c → color: ;.
  2. Value appending: Add numbers directly after letters: m10 → margin: 10px;.
  3. Default unit is px: w300 → width: 300px;.
  4. Custom units: Use p for %, e for em, r for rem, vh for vh, vw for vw.
    • w100p → width: 100%;
    • fz1.5r → font-size: 1.5rem;
    • h100vh → height: 100vh;
  5. Multiple values: Use hyphens - to separate values:
    • m10-20 → margin: 10px 20px;
    • p10-20-30-40 → padding: 10px 20px 30px 40px;

1. Display & Position Shorthands

Display Properties

ShorthandExpands ToDescription
dbdisplay: block;Block display
dndisplay: none;Hide element
didisplay: inline;Inline display
dibdisplay: inline-block;Inline block
dfdisplay: flex;Flexbox container
difdisplay: inline-flex;Inline flex container
dgdisplay: grid;Grid container

Position Properties

ShorthandExpands ToDescription
pos:a or poaposition: absolute;Absolute positioning
pos:r or porposition: relative;Relative positioning
pos:f or pofposition: fixed;Fixed positioning
pos:s or posposition: sticky;Sticky positioning
t0top: 0;Top offset
r0right: 0;Right offset
b0bottom: 0;Bottom offset
l0left: 0;Left offset
z10z-index: 10;Z-index stack layer

💡 Pro Shortcut: Type pos:a+t0+l0 and press Tab to expand position absolute with top 0 and left 0 all at once!


2. Box Model Shorthands (Margin, Padding, Width, Height)

Margin & Padding

ShorthandExpands To
m0margin: 0;
m10margin: 10px;
m10-20margin: 10px 20px;
m0-automargin: 0 auto; (Center block element)
mt10margin-top: 10px;
mr15margin-right: 15px;
mb20margin-bottom: 20px;
ml5margin-left: 5px;
p0padding: 0;
p15-30padding: 15px 30px;
pt20padding-top: 20px;
pb20padding-bottom: 20px;

Width & Height

ShorthandExpands To
w100pwidth: 100%;
w300width: 300px;
w100vwwidth: 100vw;
h100pheight: 100%;
h100vhheight: 100vh;
mw100pmax-width: 100%;
mah500max-height: 500px;

Box Sizing

ShorthandExpands To
bxz or bxz:bbbox-sizing: border-box;
bxz:cbbox-sizing: content-box;

3. Typography & Text Formatting

ShorthandExpands ToDescription
fz16font-size: 16px;Font size in px
fz1.2rfont-size: 1.2rem;Font size in rem
fwbfont-weight: bold;Bold text
fwnfont-weight: normal;Normal weight
fw700font-weight: 700;Numeric weight
lh1.5line-height: 1.5;Line height ratio
tactext-align: center;Center align text
taltext-align: left;Left align text
tartext-align: right;Right align text
tdntext-decoration: none;Remove underline from links
tdutext-decoration: underline;Underline text
ttutext-transform: uppercase;Uppercase text
ttctext-transform: capitalize;Capitalize text
wsnwwhite-space: nowrap;Prevent text wrap
lts1letter-spacing: 1px;Letter spacing

4. Colors & Backgrounds

ShorthandExpands To
c#fffcolor: #fff;
c#333color: #333;
c:rcolor: red;
bgbackground: #fff;
bgc#f5f5f5background-color: #f5f5f5;
bgibackground-image: url();
bgr:nbackground-repeat: no-repeat;
bgsz:cbackground-size: cover;
bgp:cbackground-position: center;

💡 Tip: Type bg#3b82f6 to generate background: #3b82f6; directly without typing property or hash symbol separately!


5. Flexbox Shorthands

Flexbox alignment is one of the most frequently typed CSS code blocks. Master these to save huge time:

ShorthandExpands To
dfdisplay: flex;
jccjustify-content: center;
jc:sbjustify-content: space-between;
jc:sajustify-content: space-around;
jc:fejustify-content: flex-end;
aicaic → align-items: center;
aifsalign-items: flex-start;
aifealign-items: flex-end;
fxd:cflex-direction: column;
fxw:wflex-wrap: wrap;
fx1flex: 1 1 0%;

Ultimate Flexbox Centering Trick

To center anything horizontally and vertically with flexbox:

Type this:

df+jcc+aic

Expands to:

display: flex;
justify-content: center;
align-items: center;

6. CSS Grid Shorthands

ShorthandExpands To
dgdisplay: grid;
gtcgrid-template-columns: ;
gtrgrid-template-rows: ;
gg10 or g10gap: 10px;
rg15row-gap: 15px;
cg20column-gap: 20px;
ji:cjustify-items: center;
ai:calign-items: center;

7. Borders & Shadows

ShorthandExpands To
bdborder: 1px solid #000;
bd:nborder: none;
bd1-solid-cccborder: 1px solid #ccc;
bdr10border-radius: 10px;
bdrs50pborder-radius: 50%; (Make circular element)
bxshbox-shadow: inset h v blur spread color;
ol:noutline: none;

8. Transitions & Transforms

ShorthandExpands To
trntransition: prop time type;
trn.3stransition: all .3s;
trftransform: ;
trf:stransform: scale(x, y);
trf:rtransform: rotate(angle);
trf:ttransform: translate(x, y);
op1opacity: 1;
op0.5opacity: 0.5;
cur:pcursor: pointer;

9. Comprehensive CSS Emmet Cheat Sheet

Here is a quick reference table of the most essential CSS Emmet abbreviations:

CategoryShorthandResulting CSS
Reset* { m0+p0+bxz }Universal reset rule
Center Flexdf+jcc+aicFlex center horizontal & vertical
Center Griddg+ji:c+ai:cGrid center horizontal & vertical
Dimensionsw100p+h100vhFull screen container
Margin/Paddingm0-auto / p15-20Auto centering / responsive padding
Texttac+fz18+fwb+lh1.5Styled centered heading
Link Resettdn+c#2563eb+cur:pStyled clean anchor link
Circle Avatarw50+h50+bdrs50p50px round avatar image
Card Shadowbdr8+bxshRounded box with shadow

10. Pro Tips for VS Code CSS Productivity

Tip 1: Chain Multiple CSS Rules with +

You don't need to press Tab for every single line! Chain multiple properties together with + on a single line:

Type this:

w100p+maxw1200+m0-auto+p20

Press Tab → Expands to:

width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;

Tip 2: Use Built-In Color Picker

When you hover your mouse over any HEX, RGB, or HSL color code in VS Code, an interactive Color Picker popup appears. You can visually pick colors and switch formats (HEX ↔ RGB ↔ HSL) easily!

Tip 3: Format CSS on Save with Prettier

Ensure your CSS properties are properly indented and formatted by adding this to your .vscode/settings.json:

{
  "editor.formatOnSave": true,
  "css.format.enable": true,
  "[css]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Tip 4: Hover & Peek Definition for Classes

Press Ctrl (or Cmd on Mac) and hover over any CSS class or HTML tag in your workspace to peek or jump straight to its definition across files!

Tip 5: Enable CSS Emmet in Tailwind & Styled-Components

If you use React (JSX/TSX) or Vue, make sure Emmet works inside style blocks and string literals by adding this to settings.json:

{
  "emmet.includeLanguages": {
    "javascript": "html",
    "javascriptreact": "html",
    "typescriptreact": "html",
    "postcss": "css"
  }
}

Summary — Top 10 Most Useful CSS Emmet Shorthands

  1. df → display: flex;
  2. jcc → justify-content: center;
  3. aic → align-items: center;
  4. pos:a → position: absolute;
  5. m0-auto → margin: 0 auto;
  6. w100p → width: 100%;
  7. h100vh → height: 100vh;
  8. tac → text-align: center;
  9. tdn → text-decoration: none;
  10. cur:p → cursor: pointer;

📚 Read More CSS & HTML Tutorials

Continue learning with our full collection of web development guides:

Happy styling! 🎉 Master these Emmet CSS shorthands to code stylesheets at lighting speed!

← Back to css
Share: