Edit this page

Widgets

Widgets define the data type and interface for entry fields. Netlify CMS comes with several built-in widgets. Click the widget names in the sidebar to jump to specific widget details. We’re always adding new widgets, and you can also create your own!

Widgets are specified as collection fields in the Netlify CMS config.yml file. Note that YAML syntax allows lists and objects to be written in block or inline style, and the code samples below include a mix of both.

To see working examples of all of the built-in widgets, try making a 'Kitchen Sink' collection item on the CMS demo site. (No login required: click the login button and the CMS will open.) You can refer to the demo configuration code to see how each field was configured.

Common widget options

The following options are available on all fields:

  • required: specify as false to make a field optional; defaults to true
  • hint: optionally add helper text directly below a widget. Useful for including instructions.
  • pattern: add field validation by specifying a list with a regex pattern and an error message; more extensive validation can be achieved with custom widgets

    • Example:

      - label: "Title"
        name: "title"
        widget: "string"
        pattern: [".{12,}", "Must have at least 12 characters"]
    • Note: Currently validation doesn't work on nested fields

Default widgets

Boolean

The boolean widget translates a toggle switch input to a true/false value.

  • Name: boolean
  • UI: toggle switch
  • Data type: boolean
  • Options:

    • default: accepts true or false; defaults to false
  • Example:

    - {label: "Draft", name: "draft", widget: "boolean", default: true}

Date

The date widget translates a date picker input to a date string. For saving date and time together, use the datetime widget.

  • Name: date
  • UI: date picker
  • Data type: Moment.js-formatted date string
  • Options:

    • default: accepts a date string, or an empty string to accept blank input; otherwise defaults to current date
    • format: optional; accepts Moment.js tokens; defaults to raw Date object (if supported by output format)
    • dateFormat: optional; boolean or Moment.js tokens. If true use default locale format.
    • timeFormat: optional; boolean or Moment.js tokens. If true use default locale format, false hides time-picker. Defaults to false.
  • Example:

    - label: "Birthdate"
      name: "birthdate"
      widget: "date"
      default: ""
      format: "MMM Do YY"

DateTime

The datetime widget translates a datetime picker to a datetime string. For saving the date only, use the date widget.

  • Name: datetime
  • UI: datetime picker
  • Data type: Moment.js-formatted datetime string
  • Options:

    • default: accepts a datetime string, or an empty string to accept blank input; otherwise defaults to current datetime
    • format: optional; accepts Moment.js tokens; defaults to raw Date object (if supported by output format)
    • dateFormat: optional; boolean or Moment.js tokens. If true use default locale format.
    • timeFormat: optional; boolean or Moment.js tokens. If true use default locale format, false hides time-picker.
  • Example:

    - label: "Start time"
      name: "start"
      widget: "datetime"
      default: ""
      format: "LLL"

File

The file widget allows editors to upload a file or select an existing one from the media library. The path to the file will be saved to the field as a string.

  • Name: file
  • UI: file picker button opens media gallery
  • Data type: file path string
  • Options:

    • default: accepts a file path string; defaults to null
    • media_library: media library settings to apply when a media library is opened by the current widget
    • allow_multiple: (default: true) when set to false, prevents multiple selection for any media library extension, but must be supported by the extension in use
    • config: a configuration object that will be passed directly to the media library being used - available options are determined by the library
  • Example:

    - label: "Manual PDF"
      name: "manual_pdf"
      widget: "file"
      default: "/uploads/general-manual.pdf"
      media_library:
        config:
          multiple: true

Hidden

Hidden widgets do not display in the UI. In folder collections that allow users to create new items, you will often want to set a default for hidden fields, so they will be set without requiring an input.

  • Name: hidden
  • UI: none
  • Data type: any valid data type
  • Options:

    • default: accepts any valid data type; recommended for collections that allow adding new items
  • Example:

    - {label: "Layout", name: "layout", widget: "hidden", default: "blog"}

Image

The image widget allows editors to upload an image or select an existing one from the media library. The path to the image file will be saved to the field as a string.

  • Name: image
  • UI: file picker button opens media gallery allowing image files (jpg, jpeg, webp, gif, png, bmp, tiff, svg) only; displays selected image thumbnail
  • Data type: file path string
  • Options:

    • default: accepts a file path string; defaults to null
    • media_library: media library settings to apply when a media library is opened by the current widget
    • allow_multiple: (default: true) when set to false, prevents multiple selection for any media library extension, but must be supported by the extension in use
    • config: a configuration object that will be passed directly to the media library being used - available options are determined by the library
  • Example:

    - label: "Featured Image"
      name: "thumbnail"
      widget: "image"
      default: "/uploads/chocolate-dogecoin.jpg"
      media_library:
        config:
          multiple: true

List

The list widget allows you to create a repeatable item in the UI which saves as a list of widget values. map a user-provided string with a comma delimiter into a list. You can choose any widget as a child of a list widget—even other lists.

  • Name: list
  • UI: if fields is specified, field containing a repeatable child widget, with controls for adding, deleting, and re-ordering the repeated widgets; if unspecified, a text input for entering comma-separated values
  • Data type: list of widget values
  • Options:

    • default: if fields is specified, declare defaults on the child widgets; if not, you may specify a list of strings to populate the text field
    • allow_add: if added and labeled false, button to add additional widgets disappears
    • field: a single widget field to be repeated
    • fields: a nested list of multiple widget fields to be included in each repeatable iteration
  • Example (field/fields not specified):

    - label: "Tags"
      name: "tags"
      widget: "list"
      default: ["news"]
  • Example (allow_add marked false):

    - label: "Tags"
      name: "tags"
      widget: "list"
      allow_add: false
      default: ["news"]
  • Example (with field):

    - label: "Gallery"
      name: "galleryImages"
      widget: "list"
      field: {label: Image, name: image, widget: image}
  • Example (with fields):

    - label: "Testimonials"
      name: "testimonials"
      widget: "list"
      fields:
        - {label: Quote, name: quote, widget: string, default: "Everything is awesome!"}
        - label: Author
          name: author
          widget: object
          fields:
            - {label: Name, name: name, widget: string, default: "Emmet"}
            - {label: Avatar, name: avatar, widget: image, default: "/img/emmet.jpg"}

Markdown

The markdown widget provides a full fledged text editor - which is based on slate - that allows users to format text with features such as headings and blockquotes. Users are also allowed to write in markdown by simply flipping a switch.

Please note: If you want to use your markdown editor to fill a markdown file contents after its frontmatter, you'll have to name the field body so the CMS recognizes it and saves the file accordingly.

  • Name: markdown

  • UI: full text editor

  • Data type: markdown

  • Options:

    • default: accepts markdown content
    • buttons: an array of strings representing the formatting buttons to display, all buttons shown by default. Buttons include: bold, italic, code, link, heading-one, heading-two, quote, code-block, bulleted-list, and numbered-list.
  • Example:

    - { label: 'Blog post content', name: 'body', widget: 'markdown' }

This would render as:

Markdown widget example

Please note: The markdown widget outputs a raw markdown string. Your static site generator may or may not render the markdown to HTML automatically. Consult with your static site generator's documentation for more information about rendering markdown.

Number

The number widget uses an HTML number input, saving the value as a string, integer, or floating point number.

  • Name: number
  • UI: HTML number input
  • Data type: string by default; configured by valueType option
  • Options:

    • default: accepts string or number value; defaults to empty string
    • valueType: accepts int or float; any other value results in saving as a string
    • min: accepts a number for minimum value accepted; unset by default
    • max: accepts a number for maximum value accepted; unset by default
  • Example:

    - label: "Puppy Count"
      name: "puppies"
      widget: "number"
      default: 2
      valueType: "int"
      min: 1
      max: 101

Object

The object widget allows you to group multiple widgets together, nested under a single field. You can choose any widget as a child of an object widget—even other objects.

  • Name: object
  • UI: a field containing one or more child widgets
  • Data type: list of child widget values
  • Options:

    • default: you can set defaults within each sub-field's configuration
    • fields: (required) a nested list of widget fields to include in your widget
  • Example:

    - label: "Profile"
      name: "profile"
      widget: "object"
      fields:
        - {label: "Public", name: "public", widget: "boolean", default: true}
        - {label: "Name", name: "name", widget: "string"}
        - label: "Birthdate"
          name: "birthdate"
          widget: "date"
          default: ""
          format: "MM/DD/YYYY"
        - label: "Address"
          name: "address"
          widget: "object"
          fields: 
            - {label: "Street Address", name: "street", widget: "string"}
            - {label: "City", name: "city", widget: "string"}
            - {label: "Postal Code", name: "post-code", widget: "string"}

Relation

The relation widget allows you to reference items from another collection. It provides a search input with a list of entries from the collection you're referencing, and the list automatically updates with matched entries based on what you've typed.

  • Name: relation
  • UI: text input with search result dropdown
  • Data type: data type of the value pulled from the related collection item
  • Options:

    • default: accepts any widget data type; defaults to an empty string
    • collection: (required) name of the collection being referenced (string)
    • displayFields: list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. Defaults to valueField.
    • searchFields: (required) list of one or more names of fields in the referenced collection to search for the typed value
    • valueField: (required) name of the field from the referenced collection whose value will be stored for the relation
  • Example (assuming a separate "authors" collection with "name" and "twitterHandle" fields):

    - label: "Post Author"
      name: "author"
      widget: "relation"
      collection: "authors"
      searchFields: ["name", "twitterHandle"]
      valueField: "name"
      displayFields: ["twitterHandle", "followerCount"]

    The generated UI input will search the authors collection by name and twitterHandle, and display each author's handle and follower count. On selection, the author name will be saved for the field.

Select

The select widget allows you to pick a string value from a dropdown menu.

  • Name: select
  • UI: select input
  • Data type: string or array
  • Options:

    • default: accepts a string; defaults to an empty string
    • options: (required) a list of options for the dropdown menu; can be listed in two ways:

      • string values: the label displayed in the dropdown is the value saved in the file
      • object with label and value fields: the label displays in the dropdown; the value is saved in the file
    • multiple: accepts a boolean; defaults to false
  • Example (options as strings):

    - label: "Align Content"
      name: "align"
      widget: "select"
      options: ["left", "center", "right"]
  • Example (options as objects):

    - label: "City"
      name: "airport-code"
      widget: "select"
      options:
        - { label: "Chicago", value: "ORD" }
        - { label: "Paris", value: "CDG" }
        - { label: "Tokyo", value: "HND" }
  • Example (multiple):

    - label: "Tags"
      name: "tags"
      widget: "select"
      multiple: true
      options: ["Design", "UX", "Dev"]

String

The string widget translates a basic text input to a string value. For larger textarea inputs, use the text widget.

  • Name: string
  • UI: text input
  • Data type: string
  • Options:

    • default: accepts a string; defaults to an empty string
  • Example:

    - {label: "Title", name: "title", widget: "string"}

Text

The text widget takes a multiline text field and saves it as a string. For shorter text inputs, use the string widget.

  • Name: text
  • UI: HTML textarea
  • Data type: string
  • Options:

    • default: accepts a string; defaults to an empty string
  • Example:

    - {label: "Description", name: "description", widget: "text"}
Open chat