For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/string/capitalize.md.

capitalize es-toolkit

Converts the first character of a string to uppercase and the remaining characters to lowercase.

const result = capitalize(str);

Usage

capitalize(str)

Use capitalize when you want to make only the first letter uppercase and convert the rest to lowercase. It's useful for normalizing names or titles.

import { capitalize } from 'es-toolkit/string';

// Basic usage
capitalize('hello'); // returns 'Hello'
capitalize('WORLD'); // returns 'World'
capitalize('javaScript'); // returns 'Javascript'

It also handles empty strings and single character strings correctly.

import { capitalize } from 'es-toolkit/string';

capitalize(''); // returns ''
capitalize('a'); // returns 'A'
capitalize('A'); // returns 'A'

You can use it to normalize user input or create titles.

import { capitalize } from 'es-toolkit/string';

// Normalize user names
const userName = 'john DOE';
const formattedName = userName.split(' ').map(capitalize).join(' ');
// returns 'John Doe'

// Create titles
const title = capitalize('welcome to our website');
// returns 'Welcome to our website'

Parameters

strstringrequired

The string to capitalize the first character.

Returns

Returns a new string with the first character capitalized and the rest in lowercase.

string
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.