Watch Webinar: Figma - Design to Code in 80% Less Time

Announcing Visual Copilot - Figma to production in half the time

Builder.io logo
Talk to Us
Contact Sales
Platform
Developers
Talk to Us

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

for developers

When generating code with Builder, you can generate code for any content entry.

Before generating code in Builder, make sure:

  • You have a Builder Page or Section with content

When generating code, you specify your framework, styling, and select Fast or Quality for code output type.

The image below gives an overview of where to select the main settings. The rest of this document goes into the available options in detail.

Screenshot of Visual Editor with the Generated Code feature open. There are three blocks with instructions.
1. Get Code, points to get code icon at top of Visual Editor.
2. Choose Framework, Styling, & Quality. Points to these settings in the panel that opened in step 1 (clicking Get Code).
3. Sync.

Supported frameworks include:

  • React
  • React Native
  • Qwik
  • Vue
  • Angular
  • HTML
  • Solid.js
  • Svelte

For CSS, you can choose:

  • Tailwind
  • CSS
  • Emotion (React)
  • Styled Components (React)
  • Styled JSX (React)

Builder-generated styles include clean, contextual class names, CSS variable names that align to your design system, and styled components with contextual names.

There are two types of generated code available, Fast code generation and Quality code generation.

Fast code generations leverage Builder’s proprietary AI model and open-source compiler to nearly instantly turn any Figma design file into high-performing, responsive code for any framework.

Free for all plans, Builder generates Fast code for the selected layers immediately, which is nearly instantly available. This code is best for rapid prototyping and working out quick concepts.

Quality code generations further enhance fast code generations to support your framework and styling requirements by adding an additional AI model that has been fine-tuned to generate clean, semantic code just as developers would write themselves.

Quality code generates at a more deliberate speed as AI considers the design as a whole and thoughtfully creates corresponding code.This bespoke option is more specific to your needs in that you can tell Builder's AI precisely what you want with custom instructions and prompts.

For more detail on using Quality code, read Prompting AI for customization.

To generate the code from your content entry:

  1. Open the Page or Section in the Visual Editor.
  2. For the whole content entry, make sure nothing's selected. For just a portion of the entry, select what you'd like code for.
  3. In the Visual Editor, click on the Get code icon, < >, in the upper right.
  4. In the code pane that opens, select your Framework and Styling.

The video below shows this process:

After generating the code, you can do one of the following to get your code into your codebase:

  • Copy the code by clicking on the copy icon and paste it manually into your project.
  • Sync the code automatically, which the next section covers.

To automatically sync the generated code with your local project, it helps to have Devtools installed and the dev server running.

To install Devtools and start the dev server, if needed:

  1. Expand the Sync code section on the right.
  2. Click the Sync to Your Codebase button.
  3. Copy the npm command and run it in the terminal at the root of your project.
  4. Start the dev server.

If Devtools is installed and the dev server is running:

  1. When the dev server is running and detected*, the Sync to Your Codebase button turns blue. Now, when you click it, you'll receive a prompt for the location where you'd like to sync your code.
  2. Enter the path and file name or accept the default suggestion.
  3. Click Sync.

*Detecting the dev server should only take about 2 seconds at a maximum.

The following video shows the entire process:

For more information on Devtools, visit Using Builder Devtools for Automated Integration.

As an alternative to using Devtools, you can run the generated npx command at the command line; for example, npx builder.io add ####, where #### is a hash that identifies the generated code.

The next video shows running this command and opening the synced code.

To further customize your generated code with AI:

  1. Be sure you've selected Quality for the type of code.
  2. At the bottom of the screen, select a suggestion or type in your own request.

As an example, the following video shows this process to break the content into separate components by selecting the multiple components suggestion:

The following image and example code show how AI worked to break the code up into separate components in the previous video:

Expand for example code excerpts:

CustomizableHeroLayout()

HeroSection()

FeatureSection()

Suggested prompts for code generation include the following list. By selecting any of them, Builder regenerates the code while incorporating these features:

  • Use Next.js Image: adds Next.js Image to your code.
  • Make interactive: adds interactivity such as code that supports click events.
  • Break into multiple components: refactors code into separate components.
  • Use props: adds props, making your code easier to maintain and use.
  • Use MUI: uses the Material UI design system.

For other features, type your request into the input and press Enter.

In addition to using the default prompts, you can give Builder your own instructions so that any time you generate code Builder will create it to your specifications.

Saved custom instructions persist through logging out and apply across your Organization and Space per user. That means that if you add custom instructions, they only apply to your account, whereas a teammate's custom instructions would only apply to their own account.

To add your own custom instructions:

  1. In the Generated Code panel, click the Settings wheel on the bottom left, next to the input.
  2. List your instructions by typing them in. You may also click on the suggestions to add them.
  3. When you're done, click the Save button.

The next video shows adding custom instructions:

To remove or edit your custom instructions:

  1. Click the Get Code icon to open the Generated Code panel.
  2. In the Generated Code panel, click the Settings wheel on the bottom left, next to the input.
  3. Edit or remove your instructions.
  4. When you're done, click the Save button.

The next video shows editing custom instructions:

In addition to the process outlined above, you can fully integrate Pages, Sections, and Data and take advantage of Builder's features. Visit Integrating Pages for more information.

Was this article helpful?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Newsletter

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy