📐

Trình Chuyển Đổi Đơn Vị CSS

Chuyển đổi tức thì giữa px, rem, em, pt, %, vw, vh với tỷ lệ cỡ chữ gốc tùy biến. Hỗ trợ tra cứu nhanh class Tailwind CSS.

⚡100% Client-Side🔒Zero Data Tracking✨Free & No Ads
px
px (root)
Live Preview
Typography Preview (16px)
Box
REM
1rem
font-size: 1rem;
EM
1em
font-size: 1em;
Points (pt)
12pt
font-size: 12pt;
Percent (%)
100%
font-size: 100%;
Viewport Width (vw)
0.833vw
width: 0.833vw;
Viewport Height (vh)
1.481vh
height: 1.481vh;

⚡ Common Values

Pixels (px)REMTailwind ClassAction
12px0.75remtext-xs / p-3
14px0.875remtext-sm / p-3.5
16px1remtext-base / p-4
18px1.125remtext-lg / p-4.5
20px1.25remtext-xl / p-5
24px1.5remtext-2xl / p-6
32px2remtext-3xl / p-8
40px2.5remtext-4xl / p-10
48px3remtext-5xl / p-12

What is CSS Unit Converter?

A CSS Unit Converter is a tool that helps web developers and designers convert between different CSS length units such as pixels (px), relative units (rem, em), points (pt), percentages (%), and viewport units (vw, vh). Understanding and using the right units is crucial for creating responsive, accessible, and maintainable websites. This tool makes it easy to convert between these units accurately, helping you make informed decisions about which units to use in your CSS code.

Why Unit Conversion Matters

Using the right CSS units can make or break your website's responsiveness and accessibility. Pixels (px) are absolute units that don't scale with user preferences, while relative units like rem and em scale based on font sizes, making them ideal for responsive design. Understanding the conversion between these units helps you build websites that work across all devices and respect user accessibility settings. For example, using rem units allows users with visual impairments to increase text size in their browser settings, improving accessibility.

Frequently Asked Questions

Should I use rem or em?▼

Use rem for font sizes and spacing that should scale with the root font size. Use em for spacing that should scale with the component's font size (like button padding). Rem is generally easier to maintain because it always references the root, while em can compound when elements are nested.

What's the default base font size?▼

Most browsers use 16px as the default font size for the <html> element. However, users can change this in their browser settings. This is why using rem is important - it respects the user's preference. Always assume 16px for calculations, but remember it can vary.

Can I mix px and rem in my CSS?▼

Yes, but be strategic about it. Use rem for typography and spacing to maintain scalability. Use px for things like borders (border: 1px solid), box-shadows, and very small gaps where you need pixel-perfect control. The key is consistency - document your unit usage conventions.

How do I convert my existing px-based site to rem?▼

Start by setting html { font-size: 100%; } or 62.5% (for easier math). Then systematically convert font-sizes and spacing to rem. You can use build tools like PostCSS with postcss-pxtorem to automate this. Test thoroughly at different zoom levels. Consider converting progressively, starting with typography.

What about vh units for mobile?▼

Viewport units on mobile can be tricky because the viewport height changes when the address bar shows/hides. Use min-height with vh for better results, or consider using dvh (dynamic viewport height) in modern browsers. Always test on actual mobile devices, not just browser dev tools.

Why is my em spacing doubling?▼

Em units compound - they're relative to the parent font size. If a parent has font-size: 2em and a child has padding: 1em, that padding is actually 2em relative to the root. This is why rem is often preferred for spacing - it doesn't compound and always references the root.

Should I use rem for media queries?▼

Yes! Using rem in media queries (e.g., @media (min-width: 48rem)) means your breakpoints respect user font size settings. This improves accessibility and creates a better responsive experience. A user who increases their font size will trigger breakpoints earlier, preventing text overflow.

What's the difference between vw and %?▼

vw is relative to the viewport width (1vw = 1% of viewport width), while % is relative to the parent element's width. Use vw for viewport-based sizing (like full-width sections), and % for parent-relative sizing (like a 50% wide column inside a container). vw is always relative to the viewport, regardless of parent.

Related Tools

💡Suggest Features & Open Source

Need a specific tool, app, or extension?

AnyTools is a 100% free open-source project for creators and developers. If you have an idea for a missing tool, extension, or productivity feature, let us know via email. If you're a developer and want to contribute code, our GitHub repository is always open for pull requests!

✓Fast Email Responses✓MIT Open Source on GitHub✓100% Free Forever