Need to convert text to kebab-case format? This guide covers everything about kebab-case conversion via API, including when to use kebab-case, its advantages for URLs and CSS, and implementation examples in multiple programming languages.
What is kebab-case?
kebab-case (also called dash-case or hyphen-case) is a naming convention where words are separated by hyphens and all letters are lowercase. It's called kebab-case because the words look like food on a skewer.
Example: Hello World Example becomes hello-world-example
When to Use kebab-case
kebab-case is commonly used in:
URLs
URL slugs use kebab-case for SEO-friendly, readable URLs.
CSS
CSS class names and custom properties use kebab-case.
HTML
HTML attributes and custom data attributes use kebab-case.
my-blog-post is understood as "my blog post".
Using the kebab-case Converter API
TinyFn provides a simple endpoint to convert text to kebab-case:
POST https://api.tinyfn.io/v1/text/kebabcase
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Hello World Example"
}
{
"kebab-case": "hello-world-example",
"original": "Hello World Example"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | The text to convert (required) |
preserve_numbers |
boolean | Keep numbers as-is (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/kebabcase',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: 'My Blog Post Title' })
}
);
const result = await response.json();
console.log(result['kebab-case']); // my-blog-post-title
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/kebabcase',
headers={'X-API-Key': 'your-api-key'},
json={'text': 'My Blog Post Title'}
)
result = response.json()['kebab-case']
print(result) # my-blog-post-title
cURL
curl -X POST "https://api.tinyfn.io/v1/text/kebabcase" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "My Blog Post Title"}'
Common Use Cases
- URL Slugs: Generate SEO-friendly URLs from page titles
- CSS Classes: Create consistent CSS class naming
- HTML Attributes: Generate data attributes from field names
- File Names: Create web-safe file names
- Component Names: Name web components and custom elements
Best Practices
- Use for URLs: kebab-case is the best choice for URL slugs
- CSS conventions: Follow BEM or other CSS methodologies with kebab-case
- Remove special chars: Strip special characters before converting
- Handle numbers: Decide how to treat numbers (e.g., item-1 vs item1)
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.
Try the kebab-case Converter API
Get your free API key and start converting text in seconds.
Get Free API Key