How to Create Content Types in Strapi?

Aarya Panse

Blog / How to Create Content Types in Strapi?

A content type is a blueprint that describes the type of content you can put in it as well as what structure it should take.

When you're putting a blog together in Strapi CMS, your "Blog Post" might have spaces to include a title, content, author, and publication date, amongst other things.

Collection Types vs Single Types

Collection TypesSingle Types
Think of these as repeatable content, like blog posts or products. You can create multiple entries using the same structure.These are for one-off content pieces, like your "About Page" or "Homepage". You'll only have one instance of these.

Your content types are built using three main elements

  1. Fields: These are the basic building blocks, like text boxes, numbers, or dates.
     
  2. Components: Think of these as reusable content chunks, like an "Image Gallery" that you might want to use in multiple content types.
     
  3. Dynamic Zones: These are flexible areas where you can mix and match different components.

Prerequisites for Content Type Creation

  • Make sure you can log into your Strapi admin panel
  • Check that you have a "Super Admin" role or appropriate permissions
  • Ensure you can access the Content-Type Builder

Step-by-Step Content Type Creation

Let's walk through creating your first content type:

Image: Strapi Admin Panel

Accessing the Content-Type Builder

  1. Log into your Strapi admin panel
  2. Click on "Content-Type Builder" in the left sidebar
  3. Look for the "Create new collection type" or "Create new single type" button

Choosing Your Type

  • Select "Collection Type" for repeatable content
  • Choose "Single Type" for one-off content pages

Setting Up Basic Information

  1. Display Name: Choose a clear, descriptive name (e.g., "Blog Post")
  2. API ID: This will be generated automatically, but you can customize it
  3. API Endpoint: Review the automatically generated API endpoint

Content Type Settings

  • Configure basic settings like the draft/publish system
  • Set up internationalization if needed
  • Choose visibility options

Adding Fields to Your Content Type

This is where you define what information your content type will contain:

Available Field Types

  1. Common field types include:
  2. Text (short and long)
  3. Number
  4. Date
  5. Media
  6. Boolean (true/false)
  7. Email
  8. Passowrd
  9. Enumeration (dropdown)

Essential Field Configurations

For each field, consider:

  • Required Fields: Mark fields that must be filled
  • Unique Fields: Ensure certain values aren't duplicated
  • Default Values: Set starting values for fields

Advanced Field Settings

Configure additional options:

  • Set minimum/maximum values or lengths
  • Add custom validation rules
  • Format settings for special fields

Configuring Advanced Features

Let's explore better ways to structure your content:

Setting Up Components

Components are reusable content blocks that can be shared across different content types:

Image: Strapi Components

  1. Navigate to "Components" in the Content-Type Builder
  2. Click "Create new component"
  3. Group related fields together (e.g., "SEO Metadata" component with title, description, and keywords)
  4. Choose between single and repeatable components

Implementing Dynamic Zones

Dynamic zones offer flexible content creation:

  1. Create a dynamic zone by adding it as a field
  2. Add multiple component options to the zone
  3. Allow content editors to choose which components to use and in what order
  4. Perfect for flexible page layouts or varied content sections

Establishing Relationships

Connect your content types in meaningful ways:

  1. One-to-One Relationships
  • Use for direct connections (e.g., one user profile per user
  • Select "Relation" field type
  • Choose the related content type
  • Set the relationship type to "One-to-One"
  1. One-to-Many Relationships
  • Perfect for cases like "one author has many articles"
  • Configure the relation field
  • Choose "One-to-Many" option
  • Set up the reverse relationship if needed
  1. Many-to-Many Relationships
  • Ideal for complex relationships (e.g., products in multiple categories)
  • Set up a relationship field
  • Select "Many-to-Many" option
  • Define relationship parameters

Configuring Permissions

Set up access controls:

  1. Go to Settings → Roles
  2. Select the role you want to configure
  3. Set permissions for:
    • Creating entries
    • Reading entries
    • Updating entries
    • Deleting entries

Testing and Validation

Ensure your content type works as intended:

Preview Functionality

  1. Create test entries
  2. Review how fields display
  3. Check responsive behavior
  4. Verify component rendering

API Endpoint Testing

  1. Check the auto-generated API endpoint
  2. Test GET requests to verify data retrieval
  3. Try POST requests to create new entries
  4. Verify PUT and DELETE operations

Content Entry Validation

  1. Test required field validation
  2. Verify unique field constraints
  3. Check format validations
  4. Test relationship functionality

Common Troubleshooting Steps

If issues arise:

  1. Check field configurations
  2. Verify permissions settings
  3. Review API response codes
  4. Check error messages in the admin panel

By reading this guide, you have learned to…

  1. Plan and structure your content effectively
  2. Take advantage of features like components and dynamic zones
  3. Optimize for performance and security.
  4. Develop flexible, scalable content architectures.
Aarya Panse
by Aarya Panse
Content Marketer

End Slow Growth. Put your Success on Steroids