Lodash _.capitalize() Method

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
String utilities

What You’ll Learn

By the end of this tutorial, you’ll capitalize the first letter of any string while keeping the rest unchanged using Lodash’s _.capitalize().

01

Core Syntax

Call _.capitalize(string) with any text value.

02

First Letter Only

Only index 0 changes; the remainder stays as-is.

03

UI Labels

Polish headings, names, and dynamic messages for display.

04

vs upperFirst

Understand when _.upperFirst is equivalent.

05

Input Validation

Handle empty strings and non-string edge cases safely.

06

Production Tips

Do not confuse with title case or full uppercasing.

What Is _.capitalize()?

_.capitalize() uppercases the first character of a string and leaves every other character exactly as it was. It does not lowercase the rest of the string or capitalize each word—that is the job of _.startCase().

💡
Beginner tip

Think of _.capitalize('hello, world!') as “make the first letter uppercase for display,” not “fix the entire sentence.”

Use it for greeting messages, form field previews, toast notifications, and anywhere you want a quick polish without restructuring the whole string.

📝 Syntax

Pass the string whose first character should be uppercased:

javascript
_.capitalize(string)

Syntax Rules

  • string — the input text. Coerced to string if needed.
  • First char only — characters at index 1 and beyond are untouched.
  • Return value — a new string with the first character uppercased.
  • Empty string — returns an empty string without error.
  • Not title case — internal words are not capitalized.
javascript
import capitalize from "lodash/capitalize";

const original = "hello, world!";
const result = capitalize(original);
// -> "Hello, world!"

⚡ Quick Reference

TaskCode patternResult
Basic capitalize_.capitalize('hello')Hello
Preserve rest_.capitalize('iPhone rules')IPhone rules
Empty input_.capitalize('')''
First char only_.upperFirst(str)Same as capitalize for strings
Title every word_.startCase(str)Foo Bar style
All uppercase_.toUpper(str)ENTIRE STRING
Mutates?
No

Returns a new string

Scope
Index 0

First character only

Similar
_.upperFirst()

Equivalent behavior

Not this
_.startCase()

Capitalizes each word

🧰 Parameters

Arguments to _.capitalize() and what they control:

string Required

The string to capitalize. Non-string values are coerced with String().

_.capitalize('hello')
return value New string

A copy with the first character uppercased. The original string is unchanged.

// -> 'Hello'
rest unchanged Important

Characters after index 0 keep their original casing and punctuation.

_.capitalize('hello WORLD')
empty input Edge case

An empty string returns '' without throwing.

_.capitalize('')

For capitalizing every word in a phrase, use _.startCase(). For identifier-style names, use _.camelCase().

Examples Gallery

Practical _.capitalize() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Capitalize the first letter while preserving the rest of the string.

Example 1 — Capitalize a greeting

Uppercase the first character of a casual greeting string.

javascript
import capitalize from "lodash/capitalize";

const original = "hello, world!";
const capitalized = capitalize(original);

console.log(capitalized);
// -> "Hello, world!"
Try It Yourself

How It Works

Only the h at index 0 becomes H. The comma, space, and lowercase world! stay the same.

Example 2 — Preserve internal casing

Brand names and acronyms inside the string are not altered.

javascript
import capitalize from "lodash/capitalize";

const brand = "apple iPhone";
const display = capitalize(brand);

console.log(display);
// -> "Apple iPhone"
Try It Yourself

How It Works

Lodash does not lowercase or re-case words after the first character.

Example 3 — Format a username for display

Show a polished label from raw user input in a dashboard header.

javascript
import capitalize from "lodash/capitalize";

const userName = "john_doe";
const heading = capitalize(userName);

console.log(heading);
// -> "John_doe"
Try It Yourself

How It Works

Great for quick display polish; pair with _.startCase if you need title-style formatting.

Example 4 — Handle an empty string

Safely call capitalize on empty input without errors.

javascript
import capitalize from "lodash/capitalize";

console.log(capitalize(""));
// -> ""

How It Works

Lodash returns early with an empty string—no error is thrown, which makes capitalize safe to call after optional user input.

Example 5 — Already capitalized input

Running capitalize on an already-uppercase first letter is harmless.

javascript
import capitalize from "lodash/capitalize";

const title = "Hello";
console.log(capitalize(title));
// -> "Hello"

How It Works

Uppercasing an already-uppercase first letter is a no-op for that character, so the output matches the input.

🚀 Beyond the Basics

Compare with related string case helpers.

Example 6 — capitalize vs startCase vs toUpper

Pick the right helper for greetings, titles, or shout-case.

javascript
import capitalize from "lodash/capitalize";
import startCase from "lodash/startCase";
import toUpper from "lodash/toUpper";

const input = "hello world";
console.log(capitalize(input)); // -> "Hello world"
console.log(startCase(input));  // -> "Hello World"
console.log(toUpper(input));    // -> "HELLO WORLD"

How It Works

capitalize touches one character; startCase restructures words; toUpper uppercases everything.

🧠 How _.capitalize() Works

1

Coerce to string

Lodash converts the input to a string if needed.

Input
2

Read first character

The character at index 0 is isolated for transformation.

Parse
3

Uppercase first char

That single character is converted to uppercase.

Transform
4

Concatenate remainder

The rest of the string (index 1+) is appended unchanged.

Join
=

Capitalized string returned

A display-ready string with only the first letter uppercased.

📝 Notes

  • _.capitalize() is equivalent to _.upperFirst() for strings.
  • It does not lowercase the remaining characters.
  • It does not capitalize each word—use _.startCase() for that.
  • Empty strings return '' without throwing.
  • Validate user input type before calling if your app expects strict strings.
  • Import lodash/capitalize for minimal bundle size.

Conclusion

_.capitalize() is a small but handy helper for polishing text in UI copy, notifications, and dynamic messages. One call, one character changed, zero surprises for the rest of the string.

When you need every word capitalized, switch to _.startCase(). For identifier-style names, use _.camelCase() instead.

💡 Best Practices

✅ Do

  • Use for quick first-letter polish in UI text
  • Validate empty or missing input in forms
  • Import lodash/capitalize for tree-shaking
  • Pair with trim() when cleaning user input first
  • Document when you need title case vs single capitalize

❌ Don’t

  • Expect title-case formatting from capitalize
  • Use for proper-noun localization (locale rules differ)
  • Lowercase the rest manually unless that is intentional
  • Confuse with _.camelCase for identifier conversion
  • Assume it fixes underscore-separated names into titles

Key Takeaways

Knowledge Unlocked

Five things to remember about _.capitalize()

Use these points whenever you need a quick first-letter uppercase.

5
Core concepts
🖼 02

UI polish

Great for labels and toasts.

Pattern
🔄 03

upperFirst

Functionally equivalent alias.

Related
04

Not title case

Use startCase for words.

Caveat
05

Tree-shake

Import lodash/capitalize.

Bundle

❓ Frequently Asked Questions

_.capitalize() uppercases the first character of a string and leaves all other characters unchanged.
No. Only the first character is modified. The remainder keeps its original casing.
_.startCase() capitalizes each word and inserts spaces. _.capitalize() only changes the very first character.
Yes. For strings, _.capitalize() and _.upperFirst() produce the same result in Lodash.
_.capitalize('') returns an empty string without throwing an error.
For display titles with each word capitalized, prefer _.startCase(). capitalize only fixes the first letter of the entire string.
Did you know?

_.capitalize() and _.upperFirst() are aliases in Lodash—same behavior, different name. For multi-word titles like “Jane Smith”, use _.startCase() instead of expecting capitalize to fix every word.

Practice _.capitalize() in the Live Editor

Open the Try It editor, run the examples, and experiment with your own strings.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful