# Slug

A slug input field

****

- Read more: <https://getkirby.com/docs/guide/blueprints/fields>
- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/fields/slug.php>

****

The slug field creates a text input that automatically sanitizes the typed value with our built-in sluggify method. It's perfect if you want to create IDs or class names for HTML elements or paths for files or URLs.

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=1416&amp;height=328&amp;enlarge=0"><img alt="" class="rounded" height="214" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=924&amp;height=214&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=462&amp;height=107&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=690&amp;height=160&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=924&amp;height=214&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=1380&amp;height=320&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/4a4bd8fcf7-1717846665/slug.png?width=1416&amp;height=328&amp;enlarge=0 1848w" width="924"></a></figure>

## Example

```yaml
fields:
  className:
    label: Class
    type: slug
```

## Field properties



<div class="table">
	<table class="parameters">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Default</th>

								<th>Description</th>
							</tr>
		</thead>
		<tbody>
						<tr>
				<td>
					after				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional text that will be shown after the input</td>
							</tr>
						<tr>
				<td>
					allow				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>''</code>
									</td>

								<td>Set of characters allowed in the slug</td>
							</tr>
						<tr>
				<td>
					autofocus				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the focus on this field when the form loads. Only the first field with this label gets</td>
							</tr>
						<tr>
				<td>
					before				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional text that will be shown before the input</td>
							</tr>
						<tr>
				<td>
					default				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Default value for the field, which will be used when a page/file/user is created</td>
							</tr>
						<tr>
				<td>
					disabled				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field is no longer editable and will not be saved</td>
							</tr>
						<tr>
				<td>
					font				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the font family (sans or monospace)</td>
							</tr>
						<tr>
				<td>
					help				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional help text below the field</td>
							</tr>
						<tr>
				<td>
					icon				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'url'</code>
									</td>

								<td>Changes the link icon</td>
							</tr>
						<tr>
				<td>
					label				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The field label can be set as string or associative array with translations</td>
							</tr>
						<tr>
				<td>
					maxlength				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Maximum number of allowed characters</td>
							</tr>
						<tr>
				<td>
					minlength				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Minimum number of required characters</td>
							</tr>
						<tr>
				<td>
					path				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Set prefix for the help text</td>
							</tr>
						<tr>
				<td>
					pattern				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>A regular expression, which will be used to validate the input</td>
							</tr>
						<tr>
				<td>
					placeholder				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional placeholder value that will be shown when the field is empty</td>
							</tr>
						<tr>
				<td>
					required				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>If <code class="type type-bool">true</code>, the field has to be filled in correctly to be saved.</td>
							</tr>
						<tr>
				<td>
					sync				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Name of another field that should be used to automatically update this field's value</td>
							</tr>
						<tr>
				<td>
					translate				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>If <code class="type type-bool">false</code>, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.</td>
							</tr>
						<tr>
				<td>
					when				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Conditions when the field will be shown (since 3.1.0)</td>
							</tr>
						<tr>
				<td>
					width				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'1/1'</code>
									</td>

								<td>The width of the field in the field grid, e.g. <code class="type">1/1</code>, <code class="type">1/2</code>, <code class="type">1/3</code>, <code class="type">1/4</code>, <code class="type">2/3</code>, <code class="type">3/4</code></td>
							</tr>
						<tr>
				<td>
					wizard				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>false</code>
									</td>

								<td>Set to object with keys <code class="type">field</code> and <code class="type">text</code> to add button to generate from another field</td>
							</tr>
					</tbody>
	</table>
</div>

## `allow` option

By default, the slug field will strip out or replace any non-alphabetic, non-numeric character with a simple dash. You can define a custom set of allowed characters with the `allow` option:

```yaml
fields:
  className:
    label: Class Name
    type: slug
    sync: title
    allow: a-z_
```

## `sync` option

You can sync the slug field with another field. Whenever the editor types something into the synced field, the slug field will update with a sluggified version of the input:

```yaml
fields:
  className:
    label: Class Name
    type: slug
    sync: title
```
Please note that when your field to sync uses camelCase, you still have to reference the field with all lowercase letters:

```yaml
fields:
  sectionHeadline:
    type: text
  id:
    label: Id
    type: slug
    sync: sectionheadline
```

The same applies for the `wizard` option below.

The slug field also works within blocks or structure field items to sync fields within a block/structure field item:

```yaml
fields:
  structure:
  type: structure
  fields:
    text:
      type: text
    slug:
      type: slug
      sync: text
```

## `wizard` option

If you don't want to automatically sync the slug field with the other field, you can also to do this manually when you click a button. The `wizard` option accepts a `field` to sync with and a `text` attribute for the button text.

```yaml
fields:
  identifier:
    label: Identifier
    type: slug
    wizard:
      field: input
      text: Generate!
```

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=1320&amp;height=220&amp;enlarge=0"><img alt="" class="rounded" height="154" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=924&amp;height=154&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=462&amp;height=77&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=690&amp;height=115&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=924&amp;height=154&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=1320&amp;height=220&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/fields/slug/d4ab22477c-1717846665/slug-field-wizard-option.png?width=1320&amp;height=220&amp;enlarge=0 1848w" width="924"></a></figure>

## How to use in templates/snippets

```php
<div class="<?= $page->className() ?>">
	<!-- -->
</div>
```