<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Builder.io</title>
    <description>The latest articles on DEV Community by Builder.io (@builderio).</description>
    <link>https://dev.to/builderio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F5062%2F24170c0a-24e7-40e7-acb0-2bb79830a69d.png</url>
      <title>DEV Community: Builder.io</title>
      <link>https://dev.to/builderio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/builderio"/>
    <language>en</language>
    <item>
      <title>What is an LLM (For Web Developers)</title>
      <dc:creator>Vishwas</dc:creator>
      <pubDate>Fri, 14 Mar 2025 10:03:28 +0000</pubDate>
      <link>https://dev.to/builderio/what-is-an-llm-for-web-developers-2064</link>
      <guid>https://dev.to/builderio/what-is-an-llm-for-web-developers-2064</guid>
      <description>&lt;p&gt;Large Language Models (LLMs) are changing how we build software, and not in that vague "AI is the future" way that people have been saying for years.&lt;/p&gt;

&lt;p&gt;The tool that transforms a Figma design into a fully responsive website? The assistant that writes your unit tests while you focus on core functionality? These aren't hypothetical scenarios; they're happening right now.&lt;/p&gt;

&lt;p&gt;The best part is that adding LLMs to your codebase has become surprisingly straightforward. But even with this simplicity, understanding how these models actually work is crucial for using them effectively.&lt;/p&gt;

&lt;p&gt;This guide will explain what Large Language Models actually are, how they work behind the scenes, and what you should consider when adding AI to your web projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Large Language Models (LLMs)?
&lt;/h2&gt;

&lt;p&gt;Let's build our understanding step by step, starting with the fundamentals and working our way up to large language models.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Model?
&lt;/h3&gt;

&lt;p&gt;When people talk about AI and machine learning, you'll hear the term "model" thrown around constantly.&lt;/p&gt;

&lt;p&gt;A model is basically a mathematical function that transforms inputs into outputs. But unlike traditional programming, where you'd write explicit rules, models learn patterns from data.&lt;/p&gt;

&lt;p&gt;Here's what that looks like in practice:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F781147aec9ab4b99be7db8a9e6ef2497%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F781147aec9ab4b99be7db8a9e6ef2497%3Fwidth%3D705" alt="Diagram showing Machine Learning Models divided into three types (Classification, Regression, Recommendation) with their respective inputs and outputs." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Feed a model tons of cat and dog pictures, and it learns to tell them apart (classification model)&lt;/li&gt;
&lt;li&gt;Show it housing data, and it figures out how square footage affects the price (regression model)&lt;/li&gt;
&lt;li&gt;Give it your browsing history, and it starts guessing what you might buy next (recommendation model)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The process of training models is structured: you show the model examples, measure its error using mathematical functions (like "how far off was this prediction?"), and then let it adjust its internal parameters to reduce that error. The model uses optimization algorithms to systematically improve its accuracy with each round. Do this thousands or millions of times, and eventually, it gets pretty good at complex tasks.&lt;/p&gt;

&lt;p&gt;What makes models powerful isn't fancy math or algorithms (though those help). It's the data. Models are only as good as what they're trained on. Take a housing price predictor, for example. If you only train it on housing prices in a luxurious neighborhood, it's gonna be totally lost when estimating values in rural villages—no algorithm, however sophisticated, can extract patterns from data it hasn't seen before.&lt;/p&gt;

&lt;p&gt;In the end, a model is just a function that makes predictions based on patterns it's seen before. It's not magic, just math at scale.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Language Model?
&lt;/h3&gt;

&lt;p&gt;A language model is exactly what it sounds like—a model that works with human language. At its most basic level, it tries to predict what word will come next in a sequence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Ff5fa2006657b440d9b593fc794c7c70d%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Ff5fa2006657b440d9b593fc794c7c70d%3Fwidth%3D705" alt="Diagram showing language model predicting " width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you type "The coffee is...", a language model calculates probabilities. It might think "hot" has a 30% chance of being next, "delicious" 15%, and "programming" basically 0%.&lt;/p&gt;

&lt;p&gt;The first language models were pretty basic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://web.stanford.edu/~jurafsky/slp3/3.pdf" rel="noopener noreferrer"&gt;N-gram models&lt;/a&gt; just counted how often word sequences appeared together&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://setosa.io/blog/2014/07/26/markov-chains/index.html" rel="noopener noreferrer"&gt;Markov chains&lt;/a&gt; looked at the last couple of words to guess the next one&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://stanford.edu/~shervine/teaching/cs-230/cheatsheet-recurrent-neural-networks" rel="noopener noreferrer"&gt;RNNs (Recurrent Neural Networks)&lt;/a&gt; tried to remember context from earlier in the text but weren't great at it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These older models were useful for some tasks but had major limitations. They'd quickly lose track of what was being discussed if the relevant information wasn't within their context window - which ranged from just a few words for n-grams to around 100 words for basic RNNs.&lt;/p&gt;

&lt;p&gt;Modern language models are much more sophisticated, but the core idea remains the same: predict what text should come next based on patterns learned from data.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Large Language Model?
&lt;/h3&gt;

&lt;p&gt;A large language model (LLM) is, as the name suggests, a language model that's been scaled up dramatically in three key ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt;: They're trained on vast amounts of textual data—think hundreds of billions of sentences from books, articles, websites, code repositories, and more&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parameters&lt;/strong&gt;: They have billions or trillions of adjustable internal values that determine how inputs are processed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Computation&lt;/strong&gt;: They need absurd amounts of computing power to train—the kind only big tech companies can typically afford&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What's fascinating is that once you scale these models big enough and combine them with advanced architectures, they develop capabilities nobody explicitly programmed. They don't just get better at predicting the next word—they can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate human-like text that is coherent and lengthy&lt;/li&gt;
&lt;li&gt;Follow complex instructions&lt;/li&gt;
&lt;li&gt;Break down problems step-by-step&lt;/li&gt;
&lt;li&gt;Write working software code&lt;/li&gt;
&lt;li&gt;Understand different contexts and tones in natural language&lt;/li&gt;
&lt;li&gt;Answer questions using information they've absorbed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This emergent behavior surprised even the researchers who built LLMs. Scale unlocks capabilities that smaller models just don't have.&lt;/p&gt;

&lt;h2&gt;
  
  
  How LLMs work
&lt;/h2&gt;

&lt;p&gt;When you feed text into an LLM, it first breaks everything down into "tokens," which can be words, parts of words, or even individual characters. It then processes these tokens through its neural network to predict what should come next.&lt;/p&gt;

&lt;p&gt;However, the real breakthrough behind modern LLMs is the transformer architecture (what the "T" in ChatGPT stands for), which completely changed how models process language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F1742336ab8074d24b60ecb7b2963d85d%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F1742336ab8074d24b60ecb7b2963d85d%3Fwidth%3D705" alt="A flowchart showing the basic transformer architecture for language models" width="705" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of processing text one word at a time like older models, transformers can look at entire passages at once and determine which parts should influence each other.&lt;/p&gt;

&lt;p&gt;The most important part of transformers is the "attention" mechanism, which allows the model to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Process text in parallel rather than word-by-word&lt;/li&gt;
&lt;li&gt;Consider relationships between words regardless of how far apart they are&lt;/li&gt;
&lt;li&gt;Weigh the importance of different words when generating each piece of output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under the hood, LLMs are still doing the same basic job as simpler language models—predicting what comes next—but their scale and architecture make them capable of so much more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" alt="exclamation" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The transformer model architecture is a deep learning architecture that was &lt;a href="https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf" rel="noopener noreferrer"&gt;developed by researchers at Google and is based on the multi-head attention mechanism&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How LLMs learn
&lt;/h2&gt;

&lt;p&gt;So, how do these large language models actually learn? It's just a whole lot of math, data, and computation.&lt;/p&gt;

&lt;p&gt;The model learns patterns from training data consisting of trillions of words through unsupervised learning, without requiring explicit programming of linguistic rules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F40b0a20281324619b32e7e4001af62c3%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F40b0a20281324619b32e7e4001af62c3%3Fwidth%3D705" alt="Flowchart of LLM development: Raw Text Data, Pre-training, Foundation Model, Fine-tuning, Specialized Model, RLHF, Production LLM." width="705" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LLM training typically happens in a few stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pre-training&lt;/strong&gt;: This is the foundation stage where the model learns language by predicting missing words from massive text datasets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-tuning&lt;/strong&gt;: After pre-training, the model gets more specialized training:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RLHF (Reinforcement Learning from Human Feedback)&lt;/strong&gt;: This is where models like ChatGPT get their polish:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The cool thing about this approach is that we never explicitly program rules of language or facts into the model. It learns patterns from data and then refines itself based on what humans prefer.&lt;/p&gt;

&lt;h2&gt;
  
  
  From design to code: our experience with LLMs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fe74019f9fd184346b06e5d7b2ebcd31f%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fe74019f9fd184346b06e5d7b2ebcd31f%3Fwidth%3D705" alt="Workflow showing Figma, Mitosis, and LLMs working together to transform designs into customized code." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At Builder.io, we've spent years building tools that connect design and development, and we've learned valuable lessons about effectively leveraging LLMs.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt;, our AI-powered Figma-to-code toolchain, &lt;a href="https://www.builder.io/blog/train-ai" rel="noopener noreferrer"&gt;we've trained specialized AI models&lt;/a&gt; with over 2 million data points that transform Figma designs into clean, responsive code.&lt;/p&gt;

&lt;p&gt;We don't just use a single AI model for this—that approach tends to fall apart in the real world. Instead, we've built a pipeline of specialized systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, a model transforms flat design structures into proper code hierarchies&lt;/li&gt;
&lt;li&gt;Then, our open-source &lt;a href="https://mitosis.builder.io/" rel="noopener noreferrer"&gt;Mitosis&lt;/a&gt; compiler adapts this structure to whatever framework you're using&lt;/li&gt;
&lt;li&gt;Finally, a fine-tuned LLM polishes the code to match your team's specific coding style and standards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This has dramatically cut down the time developers spend translating designs into actual working code, allowing them to focus on the stuff that matters: building great user experiences and working on the core functionality of their apps.&lt;/p&gt;

&lt;p&gt;Working with LLMs in production has taught us that the difference between a mind-blowing AI feature and a frustrating one often comes down to the integration details most people overlook.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating LLMs into web applications
&lt;/h2&gt;

&lt;p&gt;So how do you actually add LLMs to your web app? You could go down a rabbit hole, but I want to focus on the fundamentals: how to connect to these models, handle their responses, and not break the bank while doing it.&lt;/p&gt;

&lt;h3&gt;
  
  
  API integration approaches
&lt;/h3&gt;

&lt;p&gt;The most common way to integrate LLMs into web applications is through API calls to hosted models. Services like OpenAI, Anthropic, Cohere, and others provide API endpoints that accept your prompts and return responses.&lt;/p&gt;

&lt;p&gt;Here's a basic example of using fetch to call an LLM API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.llmprovider.com/generate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;max_tokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key parameters typically include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prompt&lt;/strong&gt;: What do you want the model to respond to&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Temperature&lt;/strong&gt;: How random/creative the output should be (0.0 = deterministic, 1.0 = creative)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Max tokens&lt;/strong&gt;: How long the response can be&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt;: Which model to use (affects quality, speed, and cost)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Frontend considerations
&lt;/h3&gt;

&lt;p&gt;When implementing LLMs in user-facing web applications, consider these best practices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Handle loading states&lt;/strong&gt; - LLM calls can take seconds, not milliseconds - show a spinner or typing animation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement streaming&lt;/strong&gt; - Most providers support streaming responses so you can show text as it's generated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add retry logic&lt;/strong&gt; - LLM services can hit rate limits or have outages, so build in retry mechanisms&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consider moderation&lt;/strong&gt; - If users can input their own prompts, you may need filtering to prevent misuse&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design for variability&lt;/strong&gt; - No matter what temperature you use, responses will vary each time&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Backend implementation strategies
&lt;/h3&gt;

&lt;p&gt;On the server side, consider these approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous processing&lt;/strong&gt; - For non-interactive uses, process requests in the background&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching common responses&lt;/strong&gt; - Store responses to common prompts to save money and improve speed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rate limiting&lt;/strong&gt; - Prevent abuse by implementing rate limits for LLM-based features&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt engineering&lt;/strong&gt; - The quality of your prompt directly affects the results&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validation and post-processing&lt;/strong&gt; - Validate and clean LLM outputs before using them&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Performance and cost optimization
&lt;/h3&gt;

&lt;p&gt;LLMs are powerful but can get expensive quickly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token optimization&lt;/strong&gt;: Every token (roughly 4 characters) costs money, with input and output tokens typically priced differently – so be strategic with prompt length and expected response size&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model selection&lt;/strong&gt;: Use smaller models for simpler tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batching&lt;/strong&gt;: Combine multiple requests when possible&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid approaches&lt;/strong&gt;: Use LLMs for what they're good at and traditional code for the rest&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Choose an integration approach
&lt;/h3&gt;

&lt;p&gt;You've got a few options depending on your needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Managed API services&lt;/strong&gt;: OpenAI, Anthropic, and Cohere provide simple REST APIs with comprehensive documentation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI SDK&lt;/strong&gt;: Adds a nice layer of abstraction and type safety if that's your thing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finding the right balance between these factors takes experimentation, but when done right, you can build features that would have been impossible just a few years ago.&lt;/p&gt;

&lt;h2&gt;
  
  
  The road ahead
&lt;/h2&gt;

&lt;p&gt;LLMs are genuinely changing how we build software, but in more practical and immediate ways than the hype might suggest. You don't need a PhD, technical expertise or massive infrastructure to start using them effectively in your projects.&lt;/p&gt;

&lt;p&gt;The learning curve exists, but it's more like learning a new framework than mastering quantum physics. Start with small experiments, try out the tools I've mentioned, and build from there.&lt;/p&gt;

&lt;p&gt;What's exciting isn't just what these models can do today but how quickly they're evolving. So give it a shot—you might be surprised at how quickly you can go from curiosity to shipping features powered by LLMs.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>How I use Cursor (+ my best tips)</title>
      <dc:creator>Steve Sewell</dc:creator>
      <pubDate>Wed, 12 Mar 2025 08:41:11 +0000</pubDate>
      <link>https://dev.to/builderio/how-i-use-cursor-my-best-tips-4918</link>
      <guid>https://dev.to/builderio/how-i-use-cursor-my-best-tips-4918</guid>
      <description>&lt;p&gt;I was just chatting with one of our senior engineers, and he mentioned that he barely types code anymore—he just types into the agent box in Cursor.&lt;/p&gt;

&lt;p&gt;I told him that is basically what I do these days as well (~80% of the time).&lt;/p&gt;

&lt;p&gt;This only works well for complex tasks if you know what you are doing, so let's get into how exactly I use Cursor and my best tips.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using YOLO mode
&lt;/h2&gt;

&lt;p&gt;One of the coolest features that people often overlook in Cursor is letting the agent write code until it verifies the code is correct beyond just lint. To do this, you need to turn on YOLO mode.&lt;/p&gt;

&lt;p&gt;Go to settings, scroll down, and make sure you turn YOLO mode on. Don't be scared by the name. When I first heard it, I figured I shouldn't use it, but you absolutely should, in my opinion.&lt;/p&gt;



&lt;p&gt;When you check the box, you get a bunch more options. You can give a prompt, an allow list, and/or a deny list. Here's my prompt for YOLO mode:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;any kind of tests are always allowed like vitest, npm test, nr test, etc. also basic build commands like build, tsc, etc. creating files and making directories (like touch, mkdir, etc) is always ok too&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This way, if it wants to run &lt;code&gt;mkdir&lt;/code&gt;, &lt;code&gt;tsc&lt;/code&gt;, or check for lints directly, it can. A really cool workflow is to run &lt;code&gt;tsc&lt;/code&gt;, and if there are any build errors at all, it'll just go ahead and fix them. It'll find any build errors in any file, fix them up, and iterate until the build passes. That's awesome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling complex tasks
&lt;/h2&gt;

&lt;p&gt;Let's explore how I use Cursor for more complicated things. I'm going to give it this prompt:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Create a function that converts a markdown string to an HTML string.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I like this prompt because pretty much no AI can consistently one-shot this. It can take a few iterations to figure it out.&lt;/p&gt;

&lt;p&gt;Traditionally, you'd type this in, see some code, test it by hand, come back and say, "Oh, that's not right," and go back and forth. You start to feel like your job is a bit like a QA tester. That's fine, but it's not always fun.&lt;/p&gt;

&lt;p&gt;That's why people invented automated tests and test-driven development. I'm not a fan of test-driven development in general, but when it comes to AI, I actually really am. So let's make this prompt a thousand times better, especially for non-trivial things, by adding one more line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Write tests first, then the code, then run the tests and update the code until tests pass.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I didn't have to tell Cursor anything. I didn't have to add example context files or approve it creating a test directory. It's going to find that from the &lt;code&gt;package.json&lt;/code&gt;—it's quite smart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watching the AI work
&lt;/h2&gt;

&lt;p&gt;Here's where it gets interesting. Cursor is creating a test file, and unlike most AI-generated code, we get some level of guarantee that the behavior of the code the AI writes is correct. If it passes these tests, it's at least doing something right.&lt;/p&gt;

&lt;p&gt;Now it's writing its implementation code, and it's going to run the tests. We've got six tests failed. Because I have YOLO mode on and told it it can run tests automatically, it's iterating on the code until the tests pass. And I'm doing nothing.&lt;/p&gt;



&lt;p&gt;&lt;span&gt;You do need to babysit these things. There are plenty of times when it's definitely just going off track. It's super common that I have to hit stop and say, "Wait, wait, wait, you're way off track here. Reset, recalibrate, get back on the right track."&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;In my case, eventually, all tests passed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Building on existing test suites
&lt;/h2&gt;

&lt;p&gt;Another cool thing you can do is build off an existing test suite. You can say, "Let's add a few more test cases, then make sure the code passes."&lt;/p&gt;

&lt;p&gt;In another project I work on, we have certain compilers and converters for Builder. I have this one converter that sometimes errors. What I do is I grab the code that couldn't convert from our logs every few days. I paste it into Cursor and say, "Run this code and see what doesn't compile, then write a test for that issue and then update my code until all the tests pass."&lt;/p&gt;

&lt;p&gt;It's amazing. I just do that every few days, pulling in new cases. It's a great way to improve your code's robustness.&lt;/p&gt;

&lt;h2&gt;
  
  
  UI design with Cursor
&lt;/h2&gt;

&lt;p&gt;Someone in the comments asked if you can make a design look good with Cursor. Unfortunately, Cursor and other LLMs are very bad at checking if a design looks right in your code.&lt;/p&gt;

&lt;p&gt;If you're not already familiar, you could use Builder.io (&lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;our Figma plugin&lt;/a&gt;) to convert designs to code. It gives you a certain level of guarantee, especially if you set up your design file a bit.&lt;/p&gt;

&lt;p&gt;Here is my preferred design to code workflow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fa8499ec8f0304494b8a676d8f566b8ca%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fa8499ec8f0304494b8a676d8f566b8ca%3Fwidth%3D705" alt="A designer uses Figma to create a design. Then, Builder.io is used to convert the design into code. A developer then iterates the code with an AI-enabled code editor, like Cursor." width="705" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing TypeScript errors
&lt;/h2&gt;

&lt;p&gt;Let me show you another technique I like a lot.&lt;/p&gt;

&lt;p&gt;Let's say I've been working on some code for a while, just coding away, and then I realized - ah, TypeScript issues. You run the build and hit all these errors. Here's what you do: Just go over to Cursor and say&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I've got some build errors. Run nr build to see the errors, then fix them, and then run build until build passes.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I end a lot of my work this way. I do a bunch of stuff, there's lint issues or whatever, who cares. I literally just tell Cursor to fix everything.&lt;/p&gt;



&lt;p&gt;In all projects, I usually keep a command I call "pre-PR". It's usually the build steps that run the fastest. It might not run the end-to-end tests that run in the CI, but I rarely break those. It might just run &lt;code&gt;tsc&lt;/code&gt;, Prettier, and ESLint - all the fast stuff that can quickly tell me if this is going to break the CI build or not.&lt;/p&gt;

&lt;p&gt;Then I just have Cursor run that and fix up the PR until everything passes, and it works pretty great for me, even in large and complex projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Debugging with logs and iterative fixing
&lt;/h2&gt;

&lt;p&gt;Sometimes, when you're dealing with a particularly tricky issue, it can be helpful to have Cursor output logs and then use those logs to fix the problem. Here's how I do it:&lt;/p&gt;

&lt;p&gt;Let's say we're still struggling with our original issue. We've tried a few things, but we're not getting the results we want. Here's what I do next:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I tell Cursor: "Please add logs to the code to get better visibility into what is going on so we can find the fix. I'll run the code and feed you the logs results."&lt;/li&gt;
&lt;li&gt;Cursor will add logging statements to the code at key points.&lt;/li&gt;
&lt;li&gt;I run the code and collect the log output.&lt;/li&gt;
&lt;li&gt;Then I go back to Cursor and say something like, "Here's the log output. What do you now think is causing the issue? And how do we fix it?"&lt;/li&gt;
&lt;li&gt;I paste the raw log output for Cursor to analyze.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach gives Cursor more concrete information to work with. It's like giving it a diagnostic report of what's happening inside the code.&lt;/p&gt;



&lt;p&gt;From there, Cursor can propose a more targeted fix based on the actual behavior of the code, not just its static analysis.&lt;/p&gt;

&lt;p&gt;This method is particularly useful for those hard-to-crack bugs where the issue isn't immediately obvious from just looking at the code. It's like having a junior developer who can quickly add logging, run the code, and then help you interpret the results.&lt;/p&gt;

&lt;p&gt;Remember, though, that this process might take a few iterations. You might need to add more logs, or focus on different areas of the code. But it's a powerful technique for solving complex issues with the help of AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Command K and Command I
&lt;/h2&gt;

&lt;p&gt;Let me show you a couple of other cool things you may or may not already know. These are really handy shortcuts in Cursor.&lt;/p&gt;

&lt;p&gt;Command K is great for making quick changes. For example, let's say I want to make all the fonts smaller except for the main copied text. I can just select the relevant code, hit Command K, and tell Cursor what I want to change.&lt;/p&gt;



&lt;p&gt;Command I will open up the agent. If you select some code and hit Command I, it'll put that code in the context for the agent chat. This is useful when you want to chat about or modify specific parts of your code.&lt;/p&gt;

&lt;p&gt;The main reason to use Command K instead of Command I is that it's faster. It knows we're only working with the selected code, so it's really quick. The inline UI is kind of nice too - it's simple and feels good to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminal AI with Command K
&lt;/h2&gt;

&lt;p&gt;Command K in the terminal is another favorite of mine. I love using it to save keystrokes. For example, I can say "list my five most recent git branches" and it'll do that for me.&lt;/p&gt;



&lt;p&gt;I don't bother memorizing complex git commands. I have more time and mental capacity to solve the things that matter most. Cursor just does what I want, and I love it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Autocomplete and tab navigation
&lt;/h2&gt;

&lt;p&gt;We all know about autocomplete, but let me show you something I find sometimes unintuitive in Cursor. After using this thing for over a year, I think I've figured out how to do it right most of the time.&lt;/p&gt;



&lt;p&gt;See that gray text? If I hit tab again, it's going to auto-complete me over there. The confusing part about Cursor is this "tab again" feature is a little different. Sometimes it completes code, sometimes it just jumps to the next suggestion. You've got to get a feel for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating commit messages
&lt;/h2&gt;

&lt;p&gt;You may not know that Cursor can generate commit messages for you. I always forget about this feature, but I really should use it more often. Just go over to the source control tab and hit the little magic wand icon.&lt;/p&gt;

&lt;p&gt;It's not always perfect (see the clip below 😅), but it can give you a good starting point for your commit messages.&lt;/p&gt;



&lt;h2&gt;
  
  
  The bug finder
&lt;/h2&gt;

&lt;p&gt;Let's talk about the bug finder feature. It's pretty cool. You can access it by hitting &lt;code&gt;Command Shift P&lt;/code&gt; and typing "bug finder".&lt;/p&gt;

&lt;p&gt;The bug finder compares your changes to the main branch and tries to identify potential bugs you've introduced. It's not perfect, but it can catch some issues you might have missed.&lt;/p&gt;

&lt;p&gt;For example, it might catch things like forgetting to handle zero values properly, which can bite you especially when dealing with positions in UI work.&lt;/p&gt;



&lt;h2&gt;
  
  
  Balancing AI assistance and coding skills
&lt;/h2&gt;

&lt;p&gt;A common question people ask is whether using AI tools like Cursor might lead to losing coding skills. It's a valid concern, but here's my take on it:&lt;/p&gt;

&lt;p&gt;If we define coding skills as the ability to build good products in a good way with code (which is probably what most companies are hiring for), then I don't think a person needs to hand-code software all day, every day, to maintain or increase these skills.&lt;/p&gt;

&lt;p&gt;AI can automate a lot of the basic work, which saves time and mental energy and allows you to focus on the harder problems. I can let AI, using Cursor's Composer, build out these UIs, and then when things get harder, I can jump in.&lt;/p&gt;

&lt;p&gt;In my opinion, there's no world where you can just vibe code an entire product. I've never seen anyone do it, and I don't think anyone will ever be able to do it. These AI tools are getting better, but they're also plateauing in some areas.&lt;/p&gt;

&lt;p&gt;We will always need to be fixing and manually implementing things in the code. If you don't know how to code at all, if you don't know how to debug, those are good skills to build. You will get stuck by coding and you'll need to unblock yourself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F28470e344ff5455693d9e6c07c4d2b62%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F28470e344ff5455693d9e6c07c4d2b62%3Fwidth%3D705" alt="A workflow showing the tasks between a new task and a final product. From a new task, we first ask if the task is simple or complex. If simple, we can use AI to write code, debug, and integrate a solution for the final product. If complex, we still need to code manually. " width="705" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think AI helps a senior developer the most. The best thing anyone can do is learn as many development skills as they can, and let the AI help you, but you need to actually know how to work with this code.&lt;/p&gt;

&lt;p&gt;As long as you're still working with code, you're still building coding skills. And most importantly, you're building productivity and efficiency skills. I would rather hire developers who use Cursor well than developers who refuse and hand-code everything.&lt;/p&gt;

&lt;p&gt;I want developers who work as leanly and as efficiently as possible. I can't solve hard problems for eight hours a day, every day. But I can vibe code a UI for four hours and then work two hours on really hard problems by hand, and that gets a lot more done ultimately.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/uJimjSDio_Y"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Overall, Cursor is an incredible tool. If you're just using autocomplete, you're probably missing out. Try the agent features and some of the other exciting features. Build familiarity with the types of workflows that work well, what works well with the agent, and what works well for testing.&lt;/p&gt;

&lt;p&gt;Remember, it's about delivering a better product to customers that'll ultimately drive more revenue for the business. Use these AI tools to help you do that more efficiently, but don't forget the importance of your own coding skills and problem-solving abilities.&lt;/p&gt;

&lt;p&gt;That's it for my best Cursor tips. Give them a try and see how they can improve your workflow.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cursor</category>
      <category>tooling</category>
      <category>programming</category>
    </item>
    <item>
      <title>Export Figma to CSS</title>
      <dc:creator>matt abrams</dc:creator>
      <pubDate>Wed, 12 Mar 2025 08:09:28 +0000</pubDate>
      <link>https://dev.to/builderio/export-figma-to-css-503g</link>
      <guid>https://dev.to/builderio/export-figma-to-css-503g</guid>
      <description>&lt;p&gt;Converting Figma designs into frontend code and CSS can sometimes feel less like precise engineering and more like a guessing game. A pixel here, a shade there—we try our best, but somehow, the results never look quite right—certainly not on the first few tries.&lt;/p&gt;

&lt;p&gt;Builder.io’s &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; ends this tedious process. No more eyeballing measurements or rebuilding components by hand. Just pixel-perfect CSS that works across frameworks and follows best practices.&lt;/p&gt;

&lt;p&gt;This guide will show you how to generate CSS from your Figma designs. For this post, we’ll focus on vanilla CSS, but Visual Copilot can handle many different styling patterns and libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Visual Copilot: AI-powered Figma to CSS plugin&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;At Builder.io, we’ve created Visual Copilot, an &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;AI—powered Figma—to—code toolchain&lt;/a&gt; that swiftly and accurately converts &lt;a href="https://www.builder.io/m/knowledge-center/design-to-code" rel="noopener noreferrer"&gt;designs to clean and responsive code&lt;/a&gt;. The plugin &lt;a href="https://www.builder.io/c/docs/generate-code#overview" rel="noopener noreferrer"&gt;supports several major styling solutions&lt;/a&gt;, including vanilla CSS, &lt;a href="https://www.builder.io/blog/figma-to-tailwind" rel="noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt;, Emotion, and Styled Components. Even better, getting started is a breeze.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to export Figma designs to CSS and React&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Exporting Figma designs to code with Visual Copilot is simple.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Launch the &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot Figma plugin&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Select a layer in your Figma file.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Generate code&lt;/strong&gt; button.&lt;/li&gt;
&lt;li&gt;Copy the generated &lt;code&gt;npx&lt;/code&gt; code into your code editor.&lt;/li&gt;
&lt;li&gt;Answer the prompt. Let the code generate, then customize the code further in follow-up prompts. The results are inserted directly into your project.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Export an entire admin dashboard: Figma to CSS + React
&lt;/h3&gt;

&lt;p&gt;In this short video, we’ll generate the code for an entire Figma design of an admin dashboard. We’ll export it into React components and simple, vanilla CSS:&lt;/p&gt;



&lt;p&gt;Visual Copilot has done the lion’s share of turning this design into a functional UI. It nailed the color scheme, the typography, the sidebar, the header, and the stat cards. Even more impressive, the table is near pixel-perfect. Even the delete buttons in the table rows are working. So much automation can dramatically accelerate your team’s web development work and free up your designers. No more wasted hours writing boilerplate code and fiddling with CSS properties.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Automatically responsive CSS&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;Visual Copilot also handles many core design requirements. For instance, it intelligently resizes components for any device, removing the need to write responsive coding manually. Your design fluidly transforms as screen sizes change, ensuring a perfect display across all devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Extensive framework and library support&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In addition to plain React and vanilla CSS, Visual Copilot also exports to most major frontend frameworks (&lt;a href="https://www.builder.io/blog/convert-figma-to-react-code" rel="noopener noreferrer"&gt;React&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-vue" rel="noopener noreferrer"&gt;Vue&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-svelte" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-angular" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;, Qwik, Solid) and many styling approaches (CSS modules, &lt;a href="https://www.builder.io/blog/figma-to-tailwind" rel="noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt;, Emotion, Styled Components, and Styled JSX). Even Figma to HTML is supported. This extensive compatibility ensures you'll get production-ready code that integrates flawlessly with your existing tech stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Customizable CSS and code after Figma exports&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;While Visual Copilot will analyze your design and then analyze and match your tech stack, the customizations don’t end there. You can use its CLI prompts to tweak the final output further. Ask it to add accessibility, a dark mode, or match your file organization. The sky’s the limit.&lt;/p&gt;

&lt;p&gt;For instance, our original Figma design export made the &lt;code&gt;delete&lt;/code&gt; buttons inside the table functional, which is great. But it used the browser’s built-in &lt;code&gt;window.confirm&lt;/code&gt; feature, which doesn’t match our design. In the video above, we prompt Visual Copilot to replace &lt;code&gt;window.confirm&lt;/code&gt; with a custom component using our color scheme.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How Visual Copilot’s AI generates pixel perfect CSS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ve1l0demuxlpzzd4any.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ve1l0demuxlpzzd4any.png" alt="A flow chart with logos, with white arrows pointing from Figma, to Builder AI, to Mitosis, to initial code, to fine-tuned LLM, to cusomized code. The logos for the initial and customized code sections are HTML, React, Qwik, and Vue." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visual Copilot runs through Builder AI, then a special compiler and a fine-tuned LLM. The Builder AI sees your designs and turns them into actual code (even without &lt;a href="https://www.builder.io/blog/figma-auto-layout" rel="noopener noreferrer"&gt;auto-layout&lt;/a&gt;). The compiler, called &lt;a href="https://www.builder.io/blog/mitosis-get-started" rel="noopener noreferrer"&gt;Mitosis&lt;/a&gt;, matches your framework and exports even cleaner code. The fine-tuned LLM improves the code by matching your style, structure, and patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;It's time to skip the tedious back-and-forth between designers and web developers. &lt;a href="https://www.builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt;'s Visual Copilot eliminates the frustration of near-miss implementations and endless CSS tweaking. Converting Figma designs should be fast and result in nothing less than flawless code. And now, with a few clicks, that's exactly what you'll get.&lt;/p&gt;

&lt;p&gt;For further reading on this topic, check out the following articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/figma-to-tailwind" rel="noopener noreferrer"&gt;Figma to Tailwind CSS with Visual Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/convert-figma-to-html" rel="noopener noreferrer"&gt;Figma to HTML with Visual Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/convert-figma-to-react-code" rel="noopener noreferrer"&gt;Figma to React with Visual Copilot&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>figmatocode</category>
      <category>programming</category>
    </item>
    <item>
      <title>Creating Animated Accordions with the Details Element and Modern CSS</title>
      <dc:creator>Stefan Judis</dc:creator>
      <pubDate>Mon, 10 Mar 2025 10:36:56 +0000</pubDate>
      <link>https://dev.to/builderio/creating-animated-accordions-with-the-details-element-and-modern-css-4mio</link>
      <guid>https://dev.to/builderio/creating-animated-accordions-with-the-details-element-and-modern-css-4mio</guid>
      <description>&lt;p&gt;Accordions are everywhere these days. GitHub has them on their home page right now. Figma ships them, too. I've implemented so many custom accordions that I can't count them.&lt;/p&gt;

&lt;p&gt;But I must say, today’s accordions are pretty fancy. Here's what you'll find on github.com.&lt;/p&gt;



&lt;p&gt;The accordion opens and closes with a good-looking slide animation, and when you toggle the entries, the image on the right column reflects the currently open entry.&lt;/p&gt;

&lt;p&gt;How does this work?&lt;/p&gt;

&lt;p&gt;JavaScript toggles data attributes and classes, and &lt;a href="https://www.stefanjudis.com/snippets/how-to-animate-height-with-css-grid/" rel="noopener noreferrer"&gt;the good old CSS grid &lt;/a&gt;&lt;a href="https://www.stefanjudis.com/snippets/how-to-animate-height-with-css-grid/" rel="noopener noreferrer"&gt;&lt;code&gt;0fr&lt;/code&gt;&lt;/a&gt;&lt;a href="https://www.stefanjudis.com/snippets/how-to-animate-height-with-css-grid/" rel="noopener noreferrer"&gt; to &lt;/a&gt;&lt;a href="https://www.stefanjudis.com/snippets/how-to-animate-height-with-css-grid/" rel="noopener noreferrer"&gt;&lt;code&gt;1fr&lt;/code&gt;&lt;/a&gt;&lt;a href="https://www.stefanjudis.com/snippets/how-to-animate-height-with-css-grid/" rel="noopener noreferrer"&gt; trick&lt;/a&gt; is used to open the details content with a slide transition.&lt;/p&gt;

&lt;p&gt;What If I told you you can build the same thing using only HTML and modern CSS?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://main.d3739ajl2fez28.amplifyapp.com/examples/github-accordion" rel="noopener noreferrer"&gt;Check out this version that I built&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;This example is built without any JavaScript. Without JS? Yep, there’s not a single &lt;code&gt;script&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;Let me show you how to create these fancy accordions using &lt;code&gt;details&lt;/code&gt; elements, the new &lt;code&gt;interpolate-size&lt;/code&gt; and &lt;code&gt;transition-behavior&lt;/code&gt; CSS properties, and the&lt;code&gt;:has()&lt;/code&gt; selector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F9f11ebd14b76123baf1648c3956344aed699b361599ceac8b82b05b475a65703%3FplaceholderIfAbsent%3Dtrue%26apiKey%3DYJIGb4i01jvw0SRdL5Bt%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F9f11ebd14b76123baf1648c3956344aed699b361599ceac8b82b05b475a65703%3FplaceholderIfAbsent%3Dtrue%26apiKey%3DYJIGb4i01jvw0SRdL5Bt%26width%3D24" alt="Caution icon" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Disclaimer: At the time of writing, some described CSS features are Chromium-only. However, all the features can be treated as progressive enhancement, and the accordion will still work for other browsers. The only thing missing will be the sliding animation.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Generating markup from your design&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Whenever I want to sketch something like this quick 50/50 layout, I reach for &lt;a href="https://www.builder.io/blog/figma-to-code-visual-copilot" rel="noopener noreferrer"&gt;Builder's Visual Copilot&lt;/a&gt;. Design something in Figma, import the design into Builder using &lt;a href="https://www.builder.io/c/docs/import-from-figma" rel="noopener noreferrer"&gt;the Figma plugin&lt;/a&gt;, and off you go.&lt;/p&gt;



&lt;p&gt;After Builder generates the component source code, you can either copy and paste it into your editor or go the fancy route and automatically add your codified designs to your project with a single &lt;code&gt;npx&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;You can even “talk” to your components, ask for improvements and refactorings, and export your designs to vanilla web HTML/CSS, React, Vue, and even Swift. It's pretty cool!&lt;/p&gt;

&lt;p&gt;But let's get to our vanilla accordion code!&lt;/p&gt;

&lt;h2&gt;
  
  
  The base setup
&lt;/h2&gt;

&lt;p&gt;After generating some juicy CSS, I cleaned things up a bit (AI ain't perfect yet) and ended up with the following HTML for our new accordion component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"accordion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"detailsColumn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;details&lt;/span&gt; &lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;First entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;details&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Second entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;details&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Third entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"imagesColumn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;details&lt;/code&gt; elements allow us to show and hide content by clicking on the visible &lt;code&gt;summary&lt;/code&gt; element. Additionally, the first element is already expanded by setting the &lt;code&gt;open&lt;/code&gt; attribute.&lt;/p&gt;



&lt;p&gt;Let's style the &lt;code&gt;details&lt;/code&gt; elements and make them a real accordion that only allows one entry to be open!&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing the &lt;code&gt;details&lt;/code&gt; default styling
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;details&lt;/code&gt; default styles are valuable for quick designs, but we aim for something more polished here. So, where are these triangle markers coming from?&lt;/p&gt;

&lt;p&gt;The tiny triangles are defined in the user agent stylesheets. Unfortunately, Chromium/Firefox and Webkit render them in different ways.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5e4692c18c8d4f17bf34a46ac8c2f1ef%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5e4692c18c8d4f17bf34a46ac8c2f1ef%3Fwidth%3D705" alt="A comparison of webkit and chromium/firefox, highlighting where the details default styling is located." width="705" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chromium/Firefox defines a &lt;code&gt;display: list-item&lt;/code&gt; on the &lt;code&gt;summary&lt;/code&gt; element. Similar to &lt;code&gt;li&lt;/code&gt; element, these elements come with a stylable &lt;code&gt;::marker&lt;/code&gt; pseudo-element, which can also be adjusted using the &lt;code&gt;list-style&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;To remove the triangles coming from &lt;code&gt;list-style-type: disclosure-open&lt;/code&gt;, you can either declare &lt;code&gt;list-style: none&lt;/code&gt; to remove all the &lt;code&gt;::marker&lt;/code&gt; elements or change the &lt;code&gt;display&lt;/code&gt; property to anything but &lt;code&gt;list-item&lt;/code&gt; to avoid rendering list styles at all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F723117579ed2448fbf18b5fc93a2cb68%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F723117579ed2448fbf18b5fc93a2cb68%3Fwidth%3D705" alt="A summary of the default user agent styles in Chromium." width="705" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Webkit's &lt;code&gt;details&lt;/code&gt; implementation is entirely different. For Apple's browser, we have to reach for the internal pseudo-element selector &lt;code&gt;::-webkit-details-marker&lt;/code&gt; and hide it with &lt;code&gt;display: none&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we combine both approaches, we end up with the following CSS to remove the &lt;code&gt;details&lt;/code&gt; triangles altogether.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Chromium / Firefox */&lt;/span&gt;
&lt;span class="nt"&gt;details&lt;/span&gt; &lt;span class="nt"&gt;summary&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Either remove the list style ... */&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c"&gt;/* ... or change the `display` property to something else */&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Webkit */&lt;/span&gt;
&lt;span class="nt"&gt;details&lt;/span&gt; &lt;span class="nt"&gt;summary&lt;/span&gt;&lt;span class="nd"&gt;::-webkit-details-marker&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Side note: it's not great that major browsers ship different details element implementations. Luckily, &lt;a href="https://github.com/web-platform-tests/interop/blob/main/2025/README.md#details-element" rel="noopener noreferrer"&gt;this topic is included in Interop 2025&lt;/a&gt;, so we will see improvements this year.&lt;/p&gt;

&lt;p&gt;Let's continue to make the elements a “real” accordion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting multiple &lt;code&gt;details&lt;/code&gt; to build an exclusive accordion
&lt;/h2&gt;

&lt;p&gt;Forcing all these &lt;code&gt;details&lt;/code&gt; elements to be open one at a time is a trivial task in 2025 because you only need to set the same &lt;code&gt;name&lt;/code&gt; attribute on all the elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;details&lt;/span&gt; &lt;span class="na"&gt;open&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"something"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;First entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;details&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"something"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Second entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it? Yes!&lt;/p&gt;

&lt;p&gt;Connecting the &lt;code&gt;details&lt;/code&gt; elements with the same &lt;code&gt;name&lt;/code&gt; allows only one element to be open at a time. If one &lt;code&gt;details&lt;/code&gt; element is opened, the others will be closed.&lt;/p&gt;

&lt;p&gt;However, before you slap the same &lt;code&gt;name&lt;/code&gt; attribute on all your &lt;code&gt;details&lt;/code&gt; elements, be aware that &lt;strong&gt;exclusive accordions have accessibility and UX tradeoffs&lt;/strong&gt;. In many situations, accessing information included in multiple elements is beneficial. For example, if extensive FAQs only allow one question to be open at a time, it will be terrible UX if someone wants to compare paragraphs. I would say that an exclusive accordion is “okay” for this small marketing widget, though.&lt;/p&gt;

&lt;p&gt;With these few &lt;code&gt;details&lt;/code&gt; tweaks, we implemented the core accordion functionality, and the component started to look like something real after adding some styling.&lt;/p&gt;



&lt;h2&gt;
  
  
  Animating the &lt;code&gt;details&lt;/code&gt; content
&lt;/h2&gt;

&lt;p&gt;At this stage, our &lt;code&gt;details&lt;/code&gt; elements are connected and open only one at a time, but they're not looking perfect yet. The hidden content isn't animating or transitioning. How can we make the details content “slide open”?&lt;/p&gt;

&lt;p&gt;To do that, we can reach into our CSS magic bag!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;::details-content&lt;/code&gt; — the expandable/collapsible &lt;code&gt;details&lt;/code&gt; content
&lt;/h3&gt;

&lt;p&gt;To animate and transition the hidden accordion content, we need to find a way to select it first.&lt;/p&gt;

&lt;p&gt;Wrapping everything in a &lt;code&gt;div&lt;/code&gt; might be an option, but this approach often leads to CSS hacks and spacing issues. Chromium browsers ship a new solution to avoid these wrapper elements — &lt;code&gt;::details-content&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The new pseudo-element lets us select all the content that's not the &lt;code&gt;summary&lt;/code&gt; element itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6832a8c32c82480bad1a17842274fdf6%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6832a8c32c82480bad1a17842274fdf6%3Fwidth%3D705" alt="A preview of the Chromuim " width="705" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, if you want to color everything that shows up after clicking the &lt;code&gt;summary&lt;/code&gt; element in red, you can set a background color on the &lt;code&gt;::details-content&lt;/code&gt; pseudo-element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;::details-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fcf47110f276c4d52a68f1ec40033e36b%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fcf47110f276c4d52a68f1ec40033e36b%3Fwidth%3D705" alt="An accordion menu, with one list item highlighted in red." width="705" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coloring this new pseudo-element isn't helpful, though, so let's use &lt;code&gt;::details-content&lt;/code&gt; for a sliding transition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Animating height with &lt;strong&gt;&lt;code&gt;interpolate-size&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now that we can select all the hidden content, you could think of adding an &lt;code&gt;overflow: hidden&lt;/code&gt; to transition the &lt;code&gt;height&lt;/code&gt; property, but, unfortunately, this won’t work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* This won't work yet */&lt;/span&gt;
&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;::details-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nd"&gt;::details-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can't animate from &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage" rel="noopener noreferrer"&gt;a &lt;/a&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;amp;lt;length-percentage&amp;amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage" rel="noopener noreferrer"&gt; value&lt;/a&gt; like &lt;code&gt;0&lt;/code&gt; to an &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size" rel="noopener noreferrer"&gt;intrinsic size value&lt;/a&gt; like &lt;code&gt;auto&lt;/code&gt; in CSS. Or can we?&lt;/p&gt;

&lt;p&gt;I have a surprise for you!&lt;/p&gt;

&lt;p&gt;In Chromium, you can animate from &lt;code&gt;200px&lt;/code&gt; (or other values) to &lt;code&gt;auto&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/interpolate-size" rel="noopener noreferrer"&gt;by setting &lt;/a&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/interpolate-size" rel="noopener noreferrer"&gt;&lt;code&gt;interpolate-size&lt;/code&gt;&lt;/a&gt;. The &lt;code&gt;allow-keywords&lt;/code&gt; value will instruct browsers to do some Math and allow transitioning from specific values to &lt;code&gt;auto&lt;/code&gt;, &lt;code&gt;min-content&lt;/code&gt;, and other keyword values. This new CSS property is a big deal!&lt;/p&gt;

&lt;p&gt;It should be safe to turn on &lt;code&gt;interpolate-size&lt;/code&gt; on the &lt;code&gt;:root&lt;/code&gt; element, and all included elements will inherit this new setting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;interpolate-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;allow-keywords&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now look at this.&lt;/p&gt;



&lt;p&gt;This sliding animation isn't perfect yet, but opening the &lt;code&gt;details&lt;/code&gt; element looks pretty good already. However, what's up with the closing transition?&lt;/p&gt;

&lt;h3&gt;
  
  
  Transitioning properties like &lt;code&gt;display&lt;/code&gt; or &lt;code&gt;content-visibility&lt;/code&gt; with &lt;code&gt;transition-behavior&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you inspect Chromium's &lt;code&gt;details&lt;/code&gt; toggle behavior, you'll discover that the closed &lt;code&gt;::details-content&lt;/code&gt; element includes a &lt;code&gt;content-visibility: hidden;&lt;/code&gt;. This CSS property prevents our closing slide transition from being visible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F06a90ba74c8645418ac2cd25aff10e14%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F06a90ba74c8645418ac2cd25aff10e14%3Fwidth%3D705" alt="A comparison between closed and open details elements, showing that the closed details has a " width="705" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whenever we close the &lt;code&gt;details&lt;/code&gt; element, &lt;code&gt;content-visibility: hidden;&lt;/code&gt; is applied to the &lt;code&gt;::details-content&lt;/code&gt; pseudo-element. &lt;code&gt;content-visibility&lt;/code&gt; makes any visible effect disappear immediately because there's nothing to transition when the value changes from &lt;code&gt;visible&lt;/code&gt; to &lt;code&gt;hidden&lt;/code&gt;. The element is just hidden right away.&lt;/p&gt;

&lt;p&gt;If you ever wanted to create an exit animation and realized that it wouldn’t work because &lt;code&gt;display: none&lt;/code&gt; will hide the element right away, this here is the same problem.&lt;/p&gt;

&lt;p&gt;The question is how should browsers transition discrete values (&lt;code&gt;hidden&lt;/code&gt;, &lt;code&gt;visible&lt;/code&gt;, …)?&lt;/p&gt;

&lt;p&gt;The default behavior is to flip the values immediately and ignore the fact that you defined a transition. This is why &lt;code&gt;display: none&lt;/code&gt; or &lt;code&gt;content-visibility: hidden&lt;/code&gt; are applied immediately.&lt;/p&gt;

&lt;p&gt;Luckily, there are new ways to change this behavior! To enable easier transitions, we now have &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior" rel="noopener noreferrer"&gt;the &lt;code&gt;transition-behavior&lt;/code&gt; property&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;::details-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* Enable transitioning of `content-visibility` */&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content-visibility&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;transition-behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;allow-discrete&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By setting &lt;code&gt;transition-behavior: allow-discrete&lt;/code&gt; we can tell the browser that it's okay to also transition properties that aren't based on numbers. If you allow discrete animations, the values won't be flipped immediately but at the 50% transition mark.&lt;/p&gt;

&lt;p&gt;For special cases like &lt;code&gt;display&lt;/code&gt; and &lt;code&gt;content-visibility&lt;/code&gt;, the values will only be flipped when the entire transition is over. This allows us to transition other properties and set &lt;code&gt;display: none&lt;/code&gt; at the end of a transition.&lt;/p&gt;

&lt;p&gt;When we turn on &lt;code&gt;transition-behavior&lt;/code&gt; for the &lt;code&gt;::details-content&lt;/code&gt;, the browser will only toggle to &lt;code&gt;content-visibility: hidden&lt;/code&gt; at the end of the specified transition (0.3s).&lt;/p&gt;

&lt;p&gt;And now check this out!&lt;/p&gt;



&lt;p&gt;This visual effect might not look like a big deal, but after fifteen years of web development, I'm absolutely amazed by being able to transition &lt;code&gt;height&lt;/code&gt; and animate from and to &lt;code&gt;display: none&lt;/code&gt;. This is huge!&lt;/p&gt;

&lt;p&gt;Now that our accordion looks good, how can we show images depending on the opened &lt;code&gt;details&lt;/code&gt; element?&lt;/p&gt;

&lt;h2&gt;
  
  
  Reacting to DOM changes with the &lt;code&gt;:has()&lt;/code&gt; selector
&lt;/h2&gt;

&lt;p&gt;Let's bring in the images in the right column of the accordion component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"accordion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- The left column --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"detailsColumn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;details&lt;/span&gt; &lt;span class="na"&gt;open&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"something"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;First entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;details&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"something"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Second entry&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- The right column --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"imagesColumn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Side note: to keep things simpler, I decided to treat the images as “decorative” with an empty alt attribute (alt=””). This way, we can transition opacity to show and hide the images without worrying about their exposure in the accessibility tree.&lt;/p&gt;

&lt;p&gt;The accordion should, by definition, always include the same number of &lt;code&gt;details&lt;/code&gt; and &lt;code&gt;img&lt;/code&gt; elements. Would it be possible to show and hide images depending on which &lt;code&gt;details&lt;/code&gt; element is currently open?&lt;/p&gt;

&lt;p&gt;It might be a bit adventurous, but I love using &lt;code&gt;:has()&lt;/code&gt; for these cases.&lt;/p&gt;

&lt;p&gt;Let’s hide all the images with &lt;code&gt;opacity: 0;&lt;/code&gt; and scale them up to make them appear with a nice transition when they become visible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.accordion&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s bring in some &lt;code&gt;:has()&lt;/code&gt; magic to make the images appear when their &lt;code&gt;details&lt;/code&gt; counterpart was opened.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know, this selector is a mouthful. Let's dissect it!&lt;/p&gt;

&lt;p&gt;From right to left: we want to show the image that is a first child (&lt;code&gt;img:nth-child(1)&lt;/code&gt;) inside of an &lt;code&gt;.accordion&lt;/code&gt; that includes an opened &lt;code&gt;details&lt;/code&gt; element that's also a first child (&lt;code&gt;details:nth-child(1)[open]&lt;/code&gt;). It takes a moment to wrap your head around it, I know…&lt;/p&gt;

&lt;p&gt;However, with this selector, we’re matching the position of the open &lt;code&gt;details&lt;/code&gt; element with the visible &lt;code&gt;img&lt;/code&gt; element, and we can extend it to cover all the included accordion entries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;4&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;4&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now look at this!&lt;/p&gt;



&lt;p&gt;Of course, this approach comes with a significant trade-off. To cover all the cases, you must hardcode a number of entries in your CSS. This obviously isn't great, but I'm okay with shipping a few more selectors to avoid some JavaScript &lt;code&gt;onClick&lt;/code&gt; handlers.&lt;/p&gt;

&lt;p&gt;And now we're almost done; only one tiny feature is missing.&lt;/p&gt;

&lt;p&gt;You might have noticed it: when all &lt;code&gt;details&lt;/code&gt; elements are closed, all images are hidden and, unfortunately, we can't prevent the &lt;code&gt;details&lt;/code&gt; elements from getting closed.&lt;/p&gt;

&lt;p&gt;There's &lt;a href="https://github.com/whatwg/html/issues/10864" rel="noopener noreferrer"&gt;an open HTML specification issue about this problem&lt;/a&gt;, but it doesn't seem to have gotten any traction.&lt;/p&gt;

&lt;p&gt;To work around this problem, I think it’s fair game to bring in a fallback image. Let's add a &lt;code&gt;.fallback&lt;/code&gt; image at the end of the images container…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"accordion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"detailsCol"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"imagesColumn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fallback"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;… and show this image when there are no open &lt;code&gt;details&lt;/code&gt; elements inside our &lt;code&gt;.accordion&lt;/code&gt; container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/*
  Show the `.default` image when `.accordion`
  doesn't include open `details` elements
*/&lt;/span&gt;
&lt;span class="nc"&gt;.accordion&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;:has&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;details&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="o"&gt;]))&lt;/span&gt; &lt;span class="nc"&gt;.fallback&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Et voilà!&lt;/p&gt;



&lt;p&gt;I might sound like a broken record, but I'm absolutely amazed by all this CSS magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This was a wild ride, wasn't it?&lt;/p&gt;

&lt;p&gt;In this post, we covered how to animate elements from &lt;code&gt;height: 0;&lt;/code&gt; to &lt;code&gt;height: auto;&lt;/code&gt;. We transitioned &lt;code&gt;content-visibility&lt;/code&gt; from &lt;code&gt;visible&lt;/code&gt; to &lt;code&gt;hidden&lt;/code&gt;. And we wrote a funky &lt;code&gt;:has()&lt;/code&gt; selector to react to all these details elements' opening and closing state.&lt;/p&gt;

&lt;p&gt;All these new features show that the CSS evolution is in full swing, and it's enabling us to build things that we couldn’t build before. &lt;strong&gt;And I'm so here for building more with less code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have any questions, let us know in the comments, &lt;a href="//mailto:stefanjudis@gmail.com"&gt;shoot me an email&lt;/a&gt;, or tag us on social. And if you want to catch the next article teaching all this cutting-edge webdev stuff, subscribe to our newsletter below.&lt;/p&gt;

&lt;p&gt;Until then — talk soon!&lt;/p&gt;

&lt;p&gt;Written by&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;span&gt;Stefan Judis&lt;/span&gt;
&lt;/h2&gt;

&lt;p&gt;Stefan loves getting into web performance, new technologies, and accessibility, sends out &lt;a href="https://webweekly.email/" rel="noopener noreferrer"&gt;a weekly web development newsletter&lt;/a&gt; and enjoys sharing &lt;a href="https://www.stefanjudis.com/today-i-learned/" rel="noopener noreferrer"&gt;nerdy discoveries on his blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>AI APIs in 2025</title>
      <dc:creator>Luke Stahl</dc:creator>
      <pubDate>Fri, 28 Feb 2025 11:29:25 +0000</pubDate>
      <link>https://dev.to/builderio/ai-apis-in-2025-70i</link>
      <guid>https://dev.to/builderio/ai-apis-in-2025-70i</guid>
      <description>&lt;p&gt;AI APIs give developers access to powerful pre-trained models without the need for extensive machine-learning expertise. Here’s an overview of the most popular AI APIs and how you can use them effectively in your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use AI APIs?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Save development time&lt;/strong&gt;: Instead of spending months training your models, you can start using advanced AI capabilities immediately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add advanced features easily&lt;/strong&gt;: Implement complex functionalities like natural language processing, image recognition, or predictive analytics with just a few API calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Models improve automatically&lt;/strong&gt;: As the API providers update their models, your application benefits from these improvements without any additional work on your part.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost-effective&lt;/strong&gt;: For most use cases, using an API is significantly cheaper than building and maintaining your AI infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Focus on your core product&lt;/strong&gt;: By outsourcing the complex processing of AI, you can concentrate on building the unique aspects of your application.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Popular APIs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3678f441068e4445b6a949696b1982e1%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3678f441068e4445b6a949696b1982e1%3Fwidth%3D800" alt="Open AI" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenAI
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://openai.com/api/" rel="noopener noreferrer"&gt;OpenAI's&lt;/a&gt; API offers access to various language models, including their o1 and o3 mini reasoning models. These models are designed to handle various language tasks with improved capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced text generation and completion&lt;/li&gt;
&lt;li&gt;Improved reasoning and task performance&lt;/li&gt;
&lt;li&gt;Enhanced multilingual capabilities&lt;/li&gt;
&lt;li&gt;Fine-tuning options for custom use cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a quick example of how you might use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OpenAIApi&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;openai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAIApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateBlogOutline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;openai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createChatCompletion&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;o1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;system&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You are a helpful assistant that creates blog outlines.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Create an outline for a blog post about &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;generateBlogOutline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The future of remote work&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; OpenAI uses a per-token pricing model. For the most current pricing information, please refer to OpenAI's official pricing page at &lt;a href="https://openai.com/api/pricing/" rel="noopener noreferrer"&gt;https://openai.com/api/pricing/&lt;/a&gt;. Prices may vary based on the specific model and usage volume.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" alt="icon" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The pricing structure for the o1 models may differ from previous models. Always check the official pricing page for the most up-to-date information before integrating the API into your projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Anthropic
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fb698430038a54c32a13740dfe765ed04%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fb698430038a54c32a13740dfe765ed04%3Fwidth%3D800" alt="Anthropic" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.anthropic.com/api" rel="noopener noreferrer"&gt;Anthropic&lt;/a&gt; recently launched &lt;a href="https://www.anthropic.com/claude/sonnet" rel="noopener noreferrer"&gt;Claude 3.7 Sonnet&lt;/a&gt;, their latest model to date. This hybrid reasoning model significantly improves coding, content generation, data analysis, and planning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhanced reasoning and task performance&lt;/li&gt;
&lt;li&gt;Advanced coding capabilities&lt;/li&gt;
&lt;li&gt;200K context window&lt;/li&gt;
&lt;li&gt;Computer use capabilities (in beta)&lt;/li&gt;
&lt;li&gt;Extended thinking mode for complex tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample use case:&lt;/strong&gt; Creating an AI research assistant&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Anthropic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@anthropic-ai/sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anthropic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Anthropic&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-api-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;researchTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Human: Provide a comprehensive overview of the latest research on &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.
  Include key findings, methodologies, and potential future directions.

  Assistant: Certainly! I'll provide an overview of the latest research on &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. Here's a summary of key findings, methodologies, and future directions:

  1. Key Findings:
  `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;anthropic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;claude-3.7-sonnet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;max_tokens_to_sample&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;researchTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quantum computing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;researchSummary&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;researchSummary&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; As of February 2025, Anthropic's pricing for Claude 3.7 Sonnet starts at $3 per million input tokens and $15 per million output tokens. They offer up to 90% cost savings with prompt caching and 50% cost savings with batch processing. For the most current and detailed pricing information, including any volume discounts or special offers, please refer to Anthropic's official pricing page: &lt;a href="https://www.anthropic.com/pricing#anthropic-api" rel="noopener noreferrer"&gt;https://www.anthropic.com/pricing#anthropic-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Claude 3.7 Sonnet offers a balance of advanced capabilities and competitive pricing, making it a strong contender in the AI API market. It's particularly well-suited for complex tasks like coding, content generation, and data analysis. The model is available through the Anthropic API, Amazon Bedrock, and Google Cloud's Vertex AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Vertex AI
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/vertex-ai/docs/reference" rel="noopener noreferrer"&gt;Vertex AI&lt;/a&gt; is Google's machine learning platform that offers a wide range of AI and ML services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access to multiple models, including Google's own (like &lt;a href="https://ai.google.dev/gemini-api/docs/models/gemini" rel="noopener noreferrer"&gt;Gemini Flash 2.0&lt;/a&gt;) and third-party options (such as Claude)&lt;/li&gt;
&lt;li&gt;Strong integration with other Google Cloud services&lt;/li&gt;
&lt;li&gt;Automated machine learning features for custom model training&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample use case:&lt;/strong&gt; Sentiment analysis of customer reviews&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aiplatform&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@google-cloud/aiplatform&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;analyzeSentiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;PredictionServiceClient&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aiplatform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PredictionServiceClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;apiEndpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;us-central1-aiplatform.googleapis.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instances&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;confidenceThreshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;maxPredictions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;endpoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endpointPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;us-central1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-endpoint-id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;instances&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;predictions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;analyzeSentiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I absolutely love this product! It's amazing!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; Vertex AI uses a pay-as-you-go model for prediction. The cost is based on the number of node hours used. Prices vary by region and machine type. For the most current and detailed pricing information, including rates for different machine types and regions, please refer to the official Vertex AI pricing page: &lt;a href="https://cloud.google.com/vertex-ai/pricing" rel="noopener noreferrer"&gt;https://cloud.google.com/vertex-ai/pricing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" alt="icon" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Vertex AI Prediction cannot scale to zero nodes, so there will always be a minimum charge for deployed models. Batch prediction jobs are billed after completion rather than incrementally.&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS Bedrock
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5da56d84591d400891cd319e10acbfad%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5da56d84591d400891cd319e10acbfad%3Fwidth%3D800" alt="AWS Bedrock" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/bedrock/" rel="noopener noreferrer"&gt;AWS Bedrock&lt;/a&gt; provides a single API to access various pretrained models from different providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access to models from Anthropic, AI21 Labs, Cohere, and Amazon&lt;/li&gt;
&lt;li&gt;Seamless integration with other AWS services&lt;/li&gt;
&lt;li&gt;Fine-tuning and customization options&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample use case:&lt;/strong&gt; Building a multi-lingual chatbot&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aws-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Configure AWS SDK&lt;/span&gt;
&lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-region&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bedrock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BedrockRuntime&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;translateAndRespond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetLanguage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Human: Translate the following text to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;targetLanguage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and then respond to it:
    &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;

    Assistant: Certainly! I'll translate the text and then respond to it in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;targetLanguage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.

    Translation:
    `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;modelId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;anthropic.claude-v2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;contentType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;max_tokens_to_sample&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;top_p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;stop_sequences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;Human:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bedrock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invokeModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;responseBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;responseBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;translateAndRespond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;What's the weather like today?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;French&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; AWS Bedrock pricing model allows for flexible use of different AI models while maintaining a consistent API, making it easier to experiment with various options or switch providers as needed. Check out their pricing page: &lt;a href="https://aws.amazon.com/bedrock/pricing/" rel="noopener noreferrer"&gt;https://aws.amazon.com/bedrock/pricing/&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fast inference options
&lt;/h2&gt;

&lt;p&gt;Both Groq and Cerebras offer impressive performance gains for open-source models, enabling developers to run popular OSS models at speeds that were previously unattainable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Groq
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F66a527575d1b46f3895880118bfbc1d5%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F66a527575d1b46f3895880118bfbc1d5%3Fwidth%3D800" alt="Groq" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://groq.com/" rel="noopener noreferrer"&gt;Groq&lt;/a&gt; is an AI hardware company advancing high-speed inference for large language models. Founded by former Google TPU architect Jonathan Ross, Groq has developed a unique architecture called the Language Processing Unit (LPU), which is designed to perform well in sequential processing tasks common in natural language processing.&lt;/p&gt;

&lt;p&gt;The company's LPU-based inference platform offers several key advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deterministic performance: Unlike traditional GPUs, Groq's LPUs provide consistent, predictable performance regardless of the input, which is crucial for real-time applications.&lt;/li&gt;
&lt;li&gt;Low latency: Groq's architecture is optimized for minimal latency, often achieving sub-100ms response times even for complex language models.&lt;/li&gt;
&lt;li&gt;Energy efficiency: The LPU design allows for high performance with lower power consumption compared to many GPU-based solutions.&lt;/li&gt;
&lt;li&gt;Scalability: Groq's infrastructure is designed to scale effortlessly, maintaining performance as demand increases.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Groq offers access to a variety of popular open-source models, including variants of &lt;a href="https://www.llama.com/" rel="noopener noreferrer"&gt;LLaMA&lt;/a&gt;, Mixtral, and other advanced language models. Their platform is particularly well-suited for applications that require rapid response times, such as real-time chatbots, code completion tools, and interactive AI assistants.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extremely low latency (often sub-100ms)&lt;/li&gt;
&lt;li&gt;Support for popular open-source models&lt;/li&gt;
&lt;li&gt;Easy integration with existing workflows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample use case:&lt;/strong&gt; Real-time code completion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Groq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;groq-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Groq&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;your-api-key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;completeCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;codeSnippet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chatCompletion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;system&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You are a helpful coding assistant. Complete the given code snippet.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Complete this code:\n\n&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;codeSnippet&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;llama2-70b-4096&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;max_tokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;chatCompletion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;def fibonacci(n):&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    if n &amp;lt;= 1:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;        return n&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    else:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;completeCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;completedCode&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;completedCode&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; Groq uses a token-based pricing model, with costs varying by model and input/output. Groq also offers vision and speech recognition models with separate pricing structures.&lt;/p&gt;

&lt;p&gt;For the most current and detailed pricing information, including rates for different models and capabilities, please refer to the official Groq pricing page: &lt;a href="https://groq.com/pricing/" rel="noopener noreferrer"&gt;https://groq.com/pricing/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cerebras
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F590d85f7a8b644b9a09f227333b01f10%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F590d85f7a8b644b9a09f227333b01f10%3Fwidth%3D800" alt="Cerebras" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://inference-docs.cerebras.ai/introduction" rel="noopener noreferrer"&gt;Cerebras&lt;/a&gt; is another AI hardware company known for developing the Wafer-Scale Engine (WSE) – the largest chip ever built. Their CS-2 system, powered by the WSE-2, is designed to accelerate AI workloads significantly.&lt;/p&gt;

&lt;p&gt;Key aspects of Cerebras' technology:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Large on-chip memory: The WSE-2 contains 40GB of on-chip memory, reducing data movement and improving efficiency.&lt;/li&gt;
&lt;li&gt;Fast data transfer: With 220 petabits per second of memory bandwidth, Cerebras systems can rapidly process complex AI models.&lt;/li&gt;
&lt;li&gt;Scalability: Cerebras' technology is designed to scale from single models to large, multi-cluster deployments.&lt;/li&gt;
&lt;li&gt;Model support: Capable of running a wide range of large language models, including open-source options.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cerebras offers cloud-based access to their AI computing capabilities, allowing developers to leverage high-performance hardware for training and inference tasks without needing on-premises installation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High throughput for batch processing&lt;/li&gt;
&lt;li&gt;Support for custom model deployment&lt;/li&gt;
&lt;li&gt;Scalable for enterprise-level applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample use case:&lt;/strong&gt; Bulk text classification&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Note: This is a conceptual example&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CerebrasApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cerebras-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CerebrasApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-api-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;classifyTexts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;responses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;batchClassify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cerebras-gpt-13b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Technology&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sports&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Politics&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Entertainment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;articles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apple announces new iPhone model&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lakers win NBA championship&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Senate passes new climate bill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nf"&gt;classifyTexts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;classifications&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Text: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\nClassification: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;classifications&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; Cerebras typically offers custom pricing based on usage volume and specific requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing an API
&lt;/h2&gt;

&lt;p&gt;When selecting an API, consider these factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Required features&lt;/strong&gt;: Does the API support the specific AI capabilities you need?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost&lt;/strong&gt;: How does the pricing fit your budget and expected usage?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality of documentation&lt;/strong&gt;: Is the API well-documented and easy to integrate?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Can the API handle your expected growth?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency requirements&lt;/strong&gt;: Do you need real-time responses, or is some delay acceptable?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data privacy&lt;/strong&gt;: How does the API provider handle data, and does it comply with relevant regulations?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customization options&lt;/strong&gt;: Can you fine-tune models or adapt them to your specific use case?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community and support&lt;/strong&gt;: Is there a strong developer community and reliable support from the provider?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tips for working with AI APIs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep API keys secure&lt;/strong&gt;: Use environment variables or secure vaults to store API keys, never hardcode them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor usage&lt;/strong&gt;: Set up alerts for unusual spikes in API calls to avoid unexpected costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control request frequency&lt;/strong&gt;: Respect API rate limits and implement your own rate limiting to prevent overuse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plan for errors&lt;/strong&gt;: Always include error handling to manage API downtime or unexpected responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache responses&lt;/strong&gt;: For non-dynamic queries, consider caching responses to reduce API calls and improve performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stay updated&lt;/strong&gt;: Follow the API provider's changelog and update your integration regularly to benefit from new features and improvements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize prompts&lt;/strong&gt;: For language models, crafting effective prompts can significantly improve results and reduce token usage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  AI SDK for unified API access
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3ab7ce040fb24ecb9fa1d1e3693be7cb%3Fwidth%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3ab7ce040fb24ecb9fa1d1e3693be7cb%3Fwidth%3D800" alt="AI SDK" width="800" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://sdk.vercel.ai/docs/foundations/providers-and-models" rel="noopener noreferrer"&gt;AI SDK&lt;/a&gt; offers a consistent interface for multiple AI providers. It simplifies the process of working with various AI models and services by hiding the differences between providers.&lt;/p&gt;

&lt;p&gt;This approach reduces development time and code complexity, allowing developers to switch between or compare different AI services easily. The SDK is particularly useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Experimenting with different providers to find the best fit&lt;/li&gt;
&lt;li&gt;Building applications that need to switch between providers dynamically&lt;/li&gt;
&lt;li&gt;Creating fallback mechanisms to handle API outages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a quick example of using the AI SDK with multiple providers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;OpenAIProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AnthropicProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;VertexAIProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@sdk-vercel/ai&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openAI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAIProvider&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-openai-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anthropic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AnthropicProvider&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-anthropic-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vertexAI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;VertexAIProvider&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-vertexai-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Now you can easily switch between providers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openAIResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Explain quantum computing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;openAI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anthropicResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Explain quantum computing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;anthropic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vertexAIResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Explain quantum computing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vertexAI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We've covered the major AI APIs available in 2025. Each has its own set of features, pricing models, and integration considerations.&lt;/p&gt;

&lt;p&gt;When choosing an API, consider the specific functionality you need, latency requirements, pricing structure, integration complexity, and data privacy concerns.&lt;/p&gt;

&lt;p&gt;That's it. The rest is up to you and your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For further related AI tooling articles, check out:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-github-copilot" rel="noopener noreferrer"&gt;Cursor vs GitHub Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-trae" rel="noopener noreferrer"&gt;Cursor vs Trae&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/devin-vs-cursor" rel="noopener noreferrer"&gt;$500 Devin vs $20 Cursor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/best-ai-code-editors" rel="noopener noreferrer"&gt;Best AI Code Editors 2025&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/windsurf-vs-cursor" rel="noopener noreferrer"&gt;Windsurf vs Cursor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Visual Copilot - The Best Figma to Code Plugin</title>
      <dc:creator>matt abrams</dc:creator>
      <pubDate>Wed, 26 Feb 2025 15:14:40 +0000</pubDate>
      <link>https://dev.to/builderio/visual-copilot-the-best-figma-to-code-plugin-1ah6</link>
      <guid>https://dev.to/builderio/visual-copilot-the-best-figma-to-code-plugin-1ah6</guid>
      <description>&lt;p&gt;Designers and developers have been playing a game of telephone for decades. Designers create beautiful mockups, developers interpret them, and somewhere along the way, things get lost in translation. It's like that childhood game where you whisper a message down a line of people, only to find out the last person heard something completely different.&lt;/p&gt;

&lt;p&gt;But what if we could skip the telephone game altogether? That's where Builder's &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; comes in. In this article, we’ll show you how to convert a design file into a working, polished, production-ready UI with just one click.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Copilot
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F04975fc3fb49403089a20cfbe84fb075%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F04975fc3fb49403089a20cfbe84fb075%3Fwidth%3D705" alt="A simple flow chart with logos, with white arrows pointing from Figma, to Builder AI, to Mitosis, to Initial code (logos being angular, qwik, react, and vue), to Fine-tuned LLM, to Customized code (with the same logos that were with the initial code)." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; is Builder.io’s AI-powered solution for seamlessly converting Figma designs into clean code. We’ve fine-tuned our in-house LLM to transform your designs into responsive code, components, and styling for any major front-end tech stack. It does all this in real-time and often with a single click.&lt;/p&gt;

&lt;h2&gt;
  
  
  Convert Figma designs to code
&lt;/h2&gt;

&lt;p&gt;Using Visual Copilot is intuitive and requires very little setup. To begin, make sure you’ve installed the plugin from the &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Figma community&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  One-click export to code
&lt;/h3&gt;



&lt;p&gt;Inside Figma, select a frame or layer from a design that you wish to export. Then launch the Visual Copilot plugin and click the &lt;code&gt;Export to Code&lt;/code&gt; button. After a few moments, you will see a &lt;code&gt;Success!&lt;/code&gt; message and an &lt;code&gt;npx&lt;/code&gt; command appear inside the plugin. Copy the command to your clipboard and then open your code editor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate Code in your IDE
&lt;/h3&gt;



&lt;p&gt;It’s best to run Visual Copilot’s &lt;code&gt;npx&lt;/code&gt; command inside your preferred IDE. This way it can automatically respect any AI rules you’ve added to your coding environment. Whether you prefer &lt;a href="https://www.builder.io/blog/figma-to-cursor" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-windsurf" rel="noopener noreferrer"&gt;Windsurf&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/cursor-vs-trae" rel="noopener noreferrer"&gt;Trae&lt;/a&gt;, good old &lt;a href="https://www.builder.io/blog/cursor-vs-github-copilot" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; or something else, Visual Copilot works with all of them.&lt;/p&gt;

&lt;p&gt;Open a terminal window and run that &lt;code&gt;npx&lt;/code&gt; command. A prompt will appear. Tell it what you want to build using plain English. Say something like "make a graph component. Use the &lt;a href="https://echarts.apache.org/en/index.html" rel="noopener noreferrer"&gt;&lt;code&gt;echarts&lt;/code&gt;&lt;/a&gt; library". And that’s it! Visual Copilot will check your project setup, create clean code from your exported Figma design, and drop it right into your files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatic responsiveness
&lt;/h3&gt;



&lt;p&gt;Visual Copilot will also handle many core design requirements. For example, automatic responsiveness is included out of the box. This one feature can save your team many hours. No more fiddling with CSS to get that component working on all screen sizes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Framework integration
&lt;/h3&gt;

&lt;p&gt;Visual Copilot is also framework and library agnostic. The plugin exports generated code for any major frontend framework. These include &lt;a href="https://www.builder.io/blog/convert-figma-to-react-code" rel="noopener noreferrer"&gt;React&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-angular" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-svelte" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt;, &lt;a href="https://www.builder.io/blog/figma-to-vue" rel="noopener noreferrer"&gt;Vue&lt;/a&gt;, Qwik, &lt;a href="https://www.builder.io/blog/convert-figma-to-html" rel="noopener noreferrer"&gt;pure HTML&lt;/a&gt; (that’s right, Astro fans 🚀), and more.&lt;/p&gt;

&lt;p&gt;The same goes for common styling libraries and design patterns. Using &lt;a href="https://www.builder.io/blog/figma-to-tailwind" rel="noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt;? Or maybe you’re a Styled Components type of dev? All in on Emotion? No worries—Visual Copilot will adapt to them all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bring your own design system
&lt;/h3&gt;



&lt;p&gt;A true Figma-to-code solution is about more than turning designs into generated code - it’s about turning designs into &lt;em&gt;your&lt;/em&gt; code. Visual Copilot can interface with your existing component libraries and in-house design systems using its powerful &lt;a href="https://www.builder.io/c/docs/cli-mapping" rel="noopener noreferrer"&gt;component mapping&lt;/a&gt; feature.&lt;/p&gt;

&lt;p&gt;A clever CLI command helps you map your components to a design file’s “&lt;a href="https://help.figma.com/hc/en-us/articles/360038662654-Guide-to-components-in-Figma" rel="noopener noreferrer"&gt;F&lt;/a&gt;&lt;a href="https://www.builder.io/c/docs/figma-components" rel="noopener noreferrer"&gt;igma components&lt;/a&gt;” before you start your export. This way you avoid generating random components with every Figma export. Instead, you get accurate, on-brand translations that reuse your existing code and design systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Figma to Lovable: design to full stack apps
&lt;/h2&gt;



&lt;p&gt;Sometimes you don't need to fit a design into an existing app. Sometimes you want to build something new, fast. That's where &lt;a href="https://www.builder.io/blog/lovable-builder" rel="noopener noreferrer"&gt;Visual Copilot's Lovable integration&lt;/a&gt; shines. It turns your Figma designs into deployed and working code in minutes, not hours.&lt;/p&gt;

&lt;p&gt;You get React, Tailwind, and Vite for the frontend, plus Supabase for your database needs. Want to add features? Just tell Lovable's AI what you need in plain English. Everything syncs to GitHub, and soon you'll be able to pull in new Figma design changes automatically - perfect for those early days when your layout keeps changing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Figma best practices for design-to-code conversion
&lt;/h2&gt;

&lt;p&gt;When using the Visual Copilot Figma plugin, following these best practices can significantly improve the accuracy and efficiency of the conversion process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use auto layout&lt;/strong&gt;: Implement Figma's &lt;a href="https://www.builder.io/blog/figma-auto-layout" rel="noopener noreferrer"&gt;auto layout&lt;/a&gt; feature to organize elements into responsive hierarchies. This is the single most impactful action for ensuring a smooth import.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Define images explicitly&lt;/strong&gt;: For complex designs, use Figma's export feature to help the AI model recognize elements as images or icons.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group background layers&lt;/strong&gt;: Combine layers that form background elements to simplify the structure and enhance export quality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimize overlaps and intersections&lt;/strong&gt;: Align boxes only with related components and avoid unnecessary overlapping to prevent undesired results.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid translucent effects&lt;/strong&gt;: Stick to fully opaque colors, as transparency can be challenging for AI to interpret accurately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Size text boxes correctly&lt;/strong&gt;: Keep text bounding boxes snug to their content to avoid issues with extra whitespace or unexpected line breaks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consider design sizes&lt;/strong&gt;: Create designs that closely match real-world dimensions for practical and accurate results. Address any large-scale designs within the plugin or communicate with developers for optimal outcomes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The old "telephone game" between designers and developers is finally over. Visual Copilot ends pixel-pushing, debugging CSS, and wasting time on basic DOM work. You get clean code that matches your design, works with your stack, and uses your components.&lt;/p&gt;

&lt;p&gt;Need a quick prototype? Use the Lovable integration. Working on a big app? Visual Copilot plus Component Mapping fits right in. It handles the boring stuff so you can build things that users love.&lt;/p&gt;

&lt;p&gt;The future of Figma-to-code is here, and it's simple. &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Try Visual Copilot&lt;/a&gt; - you'll wonder how you ever lived without it.&lt;/p&gt;

&lt;p&gt;For continued reading, check out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/figma-to-cursor" rel="noopener noreferrer"&gt;Figma to Code with Cursor and Visual Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/figma-to-windsurf" rel="noopener noreferrer"&gt;Figma to Code with Windsurf and Visual Copilot&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>figma</category>
      <category>programming</category>
      <category>design</category>
    </item>
    <item>
      <title>Best AI Code Editors in 2025</title>
      <dc:creator>Vishwas</dc:creator>
      <pubDate>Mon, 24 Feb 2025 11:36:15 +0000</pubDate>
      <link>https://dev.to/builderio/best-ai-code-editors-in-2025-4kaf</link>
      <guid>https://dev.to/builderio/best-ai-code-editors-in-2025-4kaf</guid>
      <description>&lt;p&gt;AI code editors have come a long way since their introduction. What started as experimental coding tools are now essential parts of many developers' daily workflows. As these editors mature, the question isn't whether to use one, but which one best suits your needs.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore the leading AI code editors of 2025, from traditional IDEs with powerful AI integrations to purpose-built AI-first editors. Let's see what each brings to your development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  VS Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; has been the go-to editor for many developers for years now. It's free, open-source, and supports just about every programming language you can think of. In 2025, through AI powerhouses like GitHub Copilot and Cline, it has evolved into a complete AI development environment while maintaining its familiarity and extensibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Copilot
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fefdd16267c5245c09ccd57976ea726ab%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fefdd16267c5245c09ccd57976ea726ab%3Fwidth%3D705" alt="Stats from github copilot, such as 55% faster coding and more than 1 million developers using the product." width="705" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/features/copilot" rel="noopener noreferrer"&gt;GitHub Copilot&lt;/a&gt;, the tool that introduced many developers to AI pair programming, has transformed from a simple code completion tool into a sophisticated pair programmer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-time code completions&lt;/li&gt;
&lt;li&gt;Context-aware and smart code suggestions based on your current code and comments&lt;/li&gt;
&lt;li&gt;Support for multiple programming languages and frameworks&lt;/li&gt;
&lt;li&gt;Seamless IDE integration&lt;/li&gt;
&lt;li&gt;Built-in chat capabilities through Copilot Chat for natural language requests&lt;/li&gt;
&lt;li&gt;Copilot Agents for extending functionality with custom AI-powered tools for documentation, data retrieval, and specialized coding tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt; Supports multiple models including &lt;code&gt;Claude 3.5 Sonnet&lt;/code&gt; from &lt;a href="https://anthropic.com" rel="noopener noreferrer"&gt;Anthropic&lt;/a&gt;, &lt;code&gt;o1&lt;/code&gt;, and &lt;code&gt;GPT-4o&lt;/code&gt; from &lt;a href="https://openai.com/" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; Free tier with 12,000 completions per month, $10/month for individuals, $19/user/month for businesses, free for students and open source contributors&lt;/p&gt;

&lt;h3&gt;
  
  
  Cline
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F26c87f40a0264b769611ef26691360b5%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F26c87f40a0264b769611ef26691360b5%3Fwidth%3D705" alt="Cline logo on a dark blue background." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Meet VS Code's other AI powerhouse. &lt;a href="https://github.com/cline/cline" rel="noopener noreferrer"&gt;Cline&lt;/a&gt; bridges the gap between editor and terminal, turning routine development tasks into streamlined workflows with its unique approach to AI assistance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Autonomous file creation and editing with diff views and &lt;code&gt;Timeline&lt;/code&gt; tracking&lt;/li&gt;
&lt;li&gt;Terminal command execution with real-time output monitoring&lt;/li&gt;
&lt;li&gt;Browser automation for testing, debugging, and UI interactions&lt;/li&gt;
&lt;li&gt;Flexible API integration with support for &lt;a href="https://openrouter.ai/" rel="noopener noreferrer"&gt;OpenRouter&lt;/a&gt;, &lt;a href="https://anthropic.com/" rel="noopener noreferrer"&gt;Anthropic&lt;/a&gt;, &lt;a href="https://openai.com/" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt;, &lt;a href="https://deepmind.google/gemini" rel="noopener noreferrer"&gt;Google Gemini&lt;/a&gt;, and local models&lt;/li&gt;
&lt;li&gt;Comprehensive context management with file structure analysis and &lt;code&gt;AST&lt;/code&gt; parsing&lt;/li&gt;
&lt;li&gt;Workspace checkpoints for comparing and restoring different versions&lt;/li&gt;
&lt;li&gt;Extensible through &lt;code&gt;Model Context Protocol&lt;/code&gt; for custom tools and capabilities&lt;/li&gt;
&lt;li&gt;Cost tracking for API usage and token consumption&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Models:&lt;/strong&gt; Supports a wide range of models from Anthropic, OpenAI, Google Gemini, DeepSeek, and local models via &lt;a href="https://lmstudio.ai/" rel="noopener noreferrer"&gt;LM Studio&lt;/a&gt; and &lt;a href="https://ollama.ai/" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; API costs vary based on chosen providers&lt;/p&gt;

&lt;h2&gt;
  
  
  Cursor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fd01466d885b740e0a30baf41f18d491b%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fd01466d885b740e0a30baf41f18d491b%3Fwidth%3D705" alt="Preview of Cursor's homepage." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine if Visual Studio Code went on a retreat, had a spiritual awakening, and came back obsessed with AI. That's basically what &lt;a href="https://www.cursor.com/" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt; is. It's built on top of VS Code, so it feels familiar, but it's packed with AI features that make you wonder if you're still actually coding or if you've somehow stepped into the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced code completion with auto-imports for TypeScript and Python&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Composer&lt;/code&gt; (&lt;code&gt;⌘ + I&lt;/code&gt;) for creating entire applications&lt;/li&gt;
&lt;li&gt;Agent mode (&lt;code&gt;⌘ + .&lt;/code&gt;) for context gathering and terminal operations&lt;/li&gt;
&lt;li&gt;Context-aware chat (&lt;code&gt;⌘ + L&lt;/code&gt;) with folder drag &amp;amp; drop support&lt;/li&gt;
&lt;li&gt;Terminal integration with natural language command processing&lt;/li&gt;
&lt;li&gt;Built-in bug finder with fix suggestions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt; &lt;code&gt;GPT-4o&lt;/code&gt;, &lt;code&gt;o1&lt;/code&gt;, &lt;code&gt;Claude 3.5 Sonnet&lt;/code&gt;, and more&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing&lt;/strong&gt; Free hobby tier, $20/month for Pro, $40/user/month for Business&lt;/p&gt;

&lt;h2&gt;
  
  
  Windsurf
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6f30446569f7409b87f7a442162dd212%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6f30446569f7409b87f7a442162dd212%3Fwidth%3D705" alt="Preview of Windsurf's home page." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Built on VS Code (sensing a theme here?), &lt;a href="https://codeium.com/windsurf" rel="noopener noreferrer"&gt;Windsurf&lt;/a&gt; offers a sophisticated AI-powered development environment with its &lt;code&gt;Supercomplete&lt;/code&gt; and &lt;code&gt;Cascade&lt;/code&gt; features. Developed by &lt;a href="https://codeium.com/" rel="noopener noreferrer"&gt;Codeium&lt;/a&gt;, it focuses on real-time workspace understanding and intelligent code assistance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Supercomplete&lt;/code&gt; for predicting and offering intelligent code suggestions with diff box previews&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Cascade&lt;/code&gt; with real-time workspace sync and iterative problem-solving&lt;/li&gt;
&lt;li&gt;Comprehensive project understanding with automatic context updates&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Flow&lt;/code&gt; technology for workspace synchronization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt; Base Model (&lt;code&gt;Llama 3.1 70B&lt;/code&gt;), Premier Model (&lt;code&gt;Llama 3.1 405B&lt;/code&gt;), plus &lt;code&gt;GPT-4o&lt;/code&gt; and &lt;code&gt;Claude 3.5 Sonnet&lt;/code&gt; with image support&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing&lt;/strong&gt; Free tier with base model access, $15/month for Pro, $60/month for Pro Ultimate&lt;/p&gt;

&lt;h2&gt;
  
  
  Trae
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F11f2ff739f7e417ebb040f651367533e%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F11f2ff739f7e417ebb040f651367533e%3Fwidth%3D705" alt="Preview of Trae's home page." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://bytedance.com" rel="noopener noreferrer"&gt;ByteDance&lt;/a&gt;, the company behind TikTok, decided to throw its hat into the AI code editor ring with &lt;a href="https://trae.ai" rel="noopener noreferrer"&gt;Trae&lt;/a&gt; (The Real AI Engineer). And surprise, surprise — it's built on VS Code. Trae might be the new kid on the block, but it's coming in hot with a polished UI and some fresh ideas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unique "think-before-doing" approach to project-wide operations&lt;/li&gt;
&lt;li&gt;Builder mode with systematic task breakdown&lt;/li&gt;
&lt;li&gt;Dual chat interfaces: Side Chat (&lt;code&gt;⌘ + U&lt;/code&gt;) and Inline Chat (&lt;code&gt;⌘ + I&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Comprehensive context system with automatic indexing&lt;/li&gt;
&lt;li&gt;Support for multimodal input including images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt; &lt;code&gt;Claude 3.5 Sonnet&lt;/code&gt; and &lt;code&gt;GPT-4o&lt;/code&gt; only&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing:&lt;/strong&gt; Currently free with all features included (future pricing to be introduced)&lt;/p&gt;

&lt;h2&gt;
  
  
  A Note About Zed
&lt;/h2&gt;

&lt;p&gt;Finally, an editor that isn't another VS Code fork! &lt;a href="https://zed.dev/" rel="noopener noreferrer"&gt;Zed&lt;/a&gt; is something different - a blazing fast editor built from the ground up in Rust, focused on raw performance and clean design. They were a bit late to the AI party, only launching their &lt;a href="https://zed.dev/blog/zed-ai" rel="noopener noreferrer"&gt;AI features in August 2024&lt;/a&gt;, and are still catching up with features that other editors have had for a while.&lt;/p&gt;

&lt;p&gt;Zed isn't yet at the level of our main contenders, but their focus on performance combined with their careful approach to AI integration makes them worth keeping an eye on.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Figma-to-IDE workflow
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F235bf26bcc3d4a20924ccce954731ec0%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F235bf26bcc3d4a20924ccce954731ec0%3Fwidth%3D705" alt="Workflow diagram showing Figma designs being converted to code through AI-powered Builder.io plugin, connecting designers to development tools." width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Workflow diagram showing Figma designs being converted to code through AI-powered Builder.io plugin, connecting designers to development tools.&lt;/p&gt;

&lt;p&gt;While we've covered the best AI code editors, it's worth mentioning that the future of development isn't just about writing code. One of my preferred workflows combines these AI tools with &lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt;, a design-to-code Figma plugin:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Design in Figma&lt;/strong&gt;: Everything starts with the design team creating pixel-perfect designs in Figma.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual Copilot&lt;/strong&gt;: Next, Visual Copilot handles the code generation process, converting these Figma designs into clean, production-ready code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-tuning in IDE&lt;/strong&gt;: While Visual Copilot handles the heavy lifting of translating design to functional code, I iterate on the generated code using the IDE's AI capabilities to add interactivity, optimize performance, and implement complex features across multiple files.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;It's 2025, and AI code editors have evolved from novelties to necessities. The tools are mature - it's just about finding the one that that best complements your coding practices and accelerates your software development process.&lt;/p&gt;

&lt;p&gt;Just remember: with great power comes great responsibility. And by responsibility, I mean "the ability to introduce bugs at superhuman speeds.”&lt;/p&gt;

&lt;p&gt;While AI coding tools are great at generating functional code and handling repetitive coding tasks, they're most effective when combined with thorough code review practices.&lt;/p&gt;

&lt;p&gt;For a more opinionated and technical deep dive, check out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-github-copilot" rel="noopener noreferrer"&gt;Cursor vs GitHub Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/devin-vs-cursor" rel="noopener noreferrer"&gt;$500 Devin vs $20 Cursor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/windsurf-vs-cursor" rel="noopener noreferrer"&gt;Windsurf vs Cursor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>tooling</category>
      <category>programming</category>
    </item>
    <item>
      <title>How Does Trae, the 100% Free AI IDE, Compare to Cursor?</title>
      <dc:creator>Vishwas</dc:creator>
      <pubDate>Tue, 18 Feb 2025 15:02:16 +0000</pubDate>
      <link>https://dev.to/builderio/how-does-trae-the-100-free-ai-ide-compare-to-cursor-3noc</link>
      <guid>https://dev.to/builderio/how-does-trae-the-100-free-ai-ide-compare-to-cursor-3noc</guid>
      <description>&lt;p&gt;Another day, another AI code editor! Just kidding - but seriously, a new AI editor called Trae just dropped. Remember when we used to joke about a new JavaScript framework dropping every day? Let's hope AI editors don't go down that road!&lt;/p&gt;

&lt;p&gt;The reality is that using an AI-powered editor is quickly becoming less of a "nice to have" and more of a "wait, you're still coding without AI?" kind of thing. While Cursor has been crushing it as the go-to AI coding sidekick, Trae has entered the scene looking to measure up.&lt;/p&gt;

&lt;p&gt;From code completion and generation to context awareness and pricing, let's break down how these tools compare where it matters most.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet the players
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.cursor.com/" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt; has established itself as a force to be reckoned with in the AI coding space. Built on &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;'s foundation, it's evolved into something far beyond a simple code editor with AI capabilities bolted on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;The new kid on the block comes from ByteDance, the company behind TikTok. &lt;a href="https://www.trae.ai/" rel="noopener noreferrer"&gt;Trae&lt;/a&gt; (cleverly named as "The Real AI Engineer"), positions itself as an adaptive AI IDE. It’s built on VS Code, just like Cursor, but it's not your typical VS Code clone. They've given the interface a fresh coat of paint, which is pretty nice to see. Best of all, it's completely free for now and packs some interesting features that make it worth a look.&lt;/p&gt;

&lt;p&gt;Let's dive into the specific features and see how these two compare.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code completion
&lt;/h2&gt;

&lt;p&gt;You know that feeling when you're typing and the IDE just &lt;em&gt;gets&lt;/em&gt; what you're trying to do? That's what we're talking about here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor's code completion is top-tier stuff. It doesn't just predict your next line - it understands your project's context and can handle everything from auto-imports in TypeScript and Python to multi-line completions that actually make sense. The suggestions feel natural, like they're coming from someone who's intimately familiar with your codebase.&lt;/p&gt;



&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae takes an interesting approach with its completion system. Hit Enter for a new line, and it starts suggesting completions based on your code context. You can either Tab to accept everything or use &lt;code&gt;Ctrl + →&lt;/code&gt; for word-by-word acceptance. Trae also encourages comment-driven generation - write what you want in a comment, and it'll try to make it happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code generation
&lt;/h2&gt;

&lt;p&gt;This is where things get interesting. Imagine describing what you want your code to do, and boom — it's there.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor combines code generation and agent capabilities in powerful ways. The Composer (⌘ + I) understands and implements entire project architectures, while Agent mode (⌘.) acts like a senior developer at your command, handling everything from context gathering to terminal operations. Together, they can scaffold entire applications while maintaining your project's style.&lt;/p&gt;



&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae's Builder mode employs a unique "think-before-doing" approach to project-wide operations. Before executing any changes, it first analyzes and confirms its understanding of the task, then breaks it down systematically. This methodical process covers everything from context extraction to file modifications and command execution, with real-time previews letting you see changes before committing.&lt;/p&gt;

&lt;p&gt;This planning-first approach mirrors an emerging trend in AI coding tools - notably, the current leader on &lt;a href="https://aider.chat/docs/leaderboards/" rel="noopener noreferrer"&gt;Aider's polyglot leaderboard&lt;/a&gt; is a combination of DeepSeek R1 for architectural planning with Claude for implementation, achieving a 64% success rate on complex coding tasks.&lt;/p&gt;

&lt;p&gt;While Trae’s approach might take slightly longer than Cursor’s direct approach, it often results in more accurate first-attempt solutions.&lt;/p&gt;



&lt;h2&gt;
  
  
  Chat
&lt;/h2&gt;

&lt;p&gt;Sometimes you just need to ask a question. But is chatting with an AI actually helpful?&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor's chat (&lt;code&gt;⌘ + L&lt;/code&gt;) is context-aware and understands what you're working on. You can drag &amp;amp; drop folders into Chat for additional context and apply code suggestions directly. It even supports images for visual context.&lt;/p&gt;



&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae offers two chat interfaces:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Side Chat (&lt;code&gt;⌘ + U&lt;/code&gt;): Works as an all-in-one AI partner, handling everything from code explanation to error fixing.&lt;/li&gt;
&lt;li&gt;Inline Chat (&lt;code&gt;⌘ + I&lt;/code&gt;): Embedded within the code editor for better flow, perfect for quick edits or code explanations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both chat modes support multimodal input, allowing you to add images like error screenshots or design drafts. You can even reference terminal output directly in your chats.&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminal integration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor extends its AI capabilities directly to the terminal with &lt;code&gt;⌘ + K&lt;/code&gt;. This lets you translate natural language descriptions into actual commands right in the terminal, making complex command-line operations more accessible. However, it hijacks the terminal's clear shortcut, which is kind of annoying.&lt;/p&gt;



&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae handles terminal operations through its chat interface rather than direct terminal integration. When you need a command, ask in the chat and Trae will provide it with two options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add to Terminal&lt;/strong&gt;: Inserts the command into your terminal, ready to run with Enter&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run&lt;/strong&gt;: Inserts the command into your terminal and executes it directly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s not as seamless as Cursor's direct terminal integration but this approach still provides the help you need for command-line operations.&lt;/p&gt;



&lt;h2&gt;
  
  
  Context awareness
&lt;/h2&gt;

&lt;p&gt;This is a big one. Can these tools actually understand your whole project, or are they just looking at the current file?&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor's pretty impressive here. It looks at your entire codebase and project structure. You can even use &lt;code&gt;@&lt;/code&gt; symbols to reference specific parts of your project, like &lt;code&gt;@Files&lt;/code&gt;, &lt;code&gt;@Folders&lt;/code&gt;, &lt;code&gt;@Code&lt;/code&gt;, and more.&lt;/p&gt;



&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae's context system is comprehensive, if a bit complex. You've got direct references, terminal output integration, and smart commands with &lt;code&gt;#Code&lt;/code&gt;, &lt;code&gt;#File&lt;/code&gt;, &lt;code&gt;#Folder&lt;/code&gt;, and &lt;code&gt;#Workspace&lt;/code&gt;. The automatic indexing for smaller projects (&amp;lt;5,000 files) is handy, though larger projects need manual indexing.&lt;/p&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Models&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's look at the AI horsepower under the hood - which models are powering these tools?&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Cursor&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Cursor offers a range of models, including GPT-4o, o1, Claude 3.5 Sonnet, and their custom cursor-small model. You can choose based on what you need — speed or capability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Trae offers a focused selection of just two high-end models: Claude 3.5 Sonnet and GPT-4o. While limited in options, these are both top-tier models known for their advanced capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code review
&lt;/h2&gt;

&lt;p&gt;We all need a second pair of eyes sometimes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor includes a powerful bug finder feature that scans your code and branch changes against main, rating potential bugs as it finds them. One click and it'll fix issues right in your editor, though each fix operation comes at a cost.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fee0ae642fa434b50b4ea074780398eb9%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fee0ae642fa434b50b4ea074780398eb9%3Fwidth%3D705" alt="A preview of Cursor's bug finder feature, scanning code on the left and producing a bug report on the right stating that " width="705" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Currently, Trae doesn't offer dedicated AI-powered code review capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI training &amp;amp; rules
&lt;/h2&gt;

&lt;p&gt;One size doesn't fit all in coding. Can you bend these tools to fit your specific needs, or are you stuck with what they give you?&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;Cursor offers two levels of AI behavior customization:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global rules&lt;/strong&gt;: Simple but powerful - modify AI behavior across your entire editor through Cursor Settings. &lt;strong&gt;&lt;code&gt;Cursor Settings&lt;/code&gt;&lt;/strong&gt;\ &amp;gt; &lt;strong&gt;&lt;code&gt;General&lt;/code&gt;&lt;/strong&gt;\ &amp;gt; &lt;strong&gt;&lt;code&gt;Rules for AI&lt;/code&gt;&lt;/strong&gt;. These rules apply to all features like Chat and Cmd+K commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project rules&lt;/strong&gt;: The recommended approach for serious development. Stored in &lt;code&gt;.cursor/rules&lt;/code&gt;, these offer granular control with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File pattern matching for specific file types&lt;/li&gt;
&lt;li&gt;Folder-specific configurations&lt;/li&gt;
&lt;li&gt;Semantic descriptions for rule application&lt;/li&gt;
&lt;li&gt;Automatic context attachment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This flexibility means you can adapt AI behavior to different frameworks, file types, or development patterns within the same project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;While Trae offers language preferences and code indexing settings, it currently doesn't support custom AI behavior rules or project-specific AI configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;Let's talk money. How do their pricing models compare?&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursor
&lt;/h3&gt;

&lt;p&gt;At $20/month for Pro and $40/user/month for Business, it's an investment in your development workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trae
&lt;/h3&gt;

&lt;p&gt;Currently, Trae is completely free - a significant advantage for developers wanting to explore AI-assisted coding without commitment. While pricing will be introduced in the future, the current free access includes all features, from the Builder mode to multimodal capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bottom line
&lt;/h2&gt;

&lt;p&gt;After putting both tools through their paces, Cursor clearly comes out on top. Its more polished experience, superior context understanding, and fluid project-wide operations make it the more capable tool for serious development work.&lt;/p&gt;

&lt;p&gt;That said, Trae offers an interesting proposition right now: it's free. While it may not match Cursor feature-for-feature, it's a solid platform for experiencing how AI can accelerate your coding workflow, especially with repetitive tasks.&lt;/p&gt;

&lt;p&gt;My recommendation? Use Trae to build your AI-assisted development habits now, then upgrade to Cursor when you're ready to invest in a more powerful toolkit.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;My preferred AI stack&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F43353ef34b1d43fbb874d8378d7c9639%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F43353ef34b1d43fbb874d8378d7c9639%3Fwidth%3D705" alt="A flow chart of the designer creating a design in figma, using builder's design to code, then passing it on to the developer to use cursor to further build and refine the code." width="705" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My preferred workflow looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Our design team works in Figma&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.figma.com/community/plugin/747985167520967365" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; converts the designs to code&lt;/li&gt;
&lt;li&gt;I iterate on the code using Cursor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you enjoyed this post, you might also like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-github-copilot" rel="noopener noreferrer"&gt;Cursor vs GitHub Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/devin-vs-cursor" rel="noopener noreferrer"&gt;$500 Devin vs $20 Cursor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/windsurf-vs-cursor" rel="noopener noreferrer"&gt;Windsurf vs Cursor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cursor</category>
      <category>ai</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Figma to Code with Windsurf and Visual Copilot</title>
      <dc:creator>Vishwas</dc:creator>
      <pubDate>Wed, 12 Feb 2025 10:57:40 +0000</pubDate>
      <link>https://dev.to/builderio/figma-to-code-with-windsurf-and-visual-copilot-19m8</link>
      <guid>https://dev.to/builderio/figma-to-code-with-windsurf-and-visual-copilot-19m8</guid>
      <description>&lt;p&gt;Converting Figma designs into functional interfaces is typically a tedious process. Recreating every pixel-perfect design detail—fonts, spacing, responsive layouts, and interactions—in HTML, CSS, and JavaScript (or any other stack) is like retyping a book that's already been written.&lt;/p&gt;

&lt;p&gt;The good news is that this level of manual work might finally be on its way out. The &lt;strong&gt;Windsurf&lt;/strong&gt; and &lt;strong&gt;Visual Copilot&lt;/strong&gt; integration eliminates this manual design-to-code work, freeing up time to focus on building features and delivering great products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windsurf
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://codeium.com/windsurf" rel="noopener noreferrer"&gt;Windsurf&lt;/a&gt; is an AI-powered IDE developed by Codeium, built on top of Visual Studio Code. Its standout feature is the "Flow" technology, which maintains real-time sync with the workspace, enabling seamless AI collaboration across projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Copilot
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; is &lt;a href="https://www.builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt;’s AI-powered Figma to code toolchain that leverages AI models to convert Figma designs into React, Vue, Svelte, Angular, HTML, etc code in real-time. It can even reuse your existing components in the output and use any styling library or design system you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up your workflow
&lt;/h2&gt;

&lt;p&gt;Getting started is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the &lt;a href="https://www.figma.com/community/plugin/747985167520967365" rel="noopener noreferrer"&gt;Visual Copilot plugin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download &lt;a href="https://codeium.com/windsurf" rel="noopener noreferrer"&gt;Windsurf&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to turn Figma designs into code
&lt;/h2&gt;

&lt;p&gt;Visual Copilot works with all popular frameworks like React, Vue, Svelte, and Angular. It also works with style tools like Tailwind CSS, Emotion and Styled Components. Whether you're building a simple landing page or a complex application, Visual Copilot can generate the code you need in your preferred tech stack. Here's how to use it:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: launch the Visual Copilot Figma plugin
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fe3097a9f506544ac8130835410ae88de%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fe3097a9f506544ac8130835410ae88de%3Fwidth%3D705" alt="Figma plugin search interface showing Builder.io AI-Powered Figma to Code plugin in the Plugins &amp;amp; widgets section." width="705" height="705"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figma plugin search interface showing &lt;a href="http://builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt; AI-Powered Figma to Code plugin in the Plugins &amp;amp; widgets section.&lt;/p&gt;

&lt;p&gt;In Figma, open the Actions menu from the toolbar, click the Plugins &amp;amp; widgets tab, search for "Builder.io AI-powered Figma to Code" plugin and run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" alt="exclamation" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also &lt;a href="https://www.figma.com/community/plugin/747985167520967365" rel="noopener noreferrer"&gt;try the plugin&lt;/a&gt; from the Figma community page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: export to code
&lt;/h3&gt;



&lt;p&gt;Select the design to convert, check the preview in the plugin, and click &lt;strong&gt;Export to Code&lt;/strong&gt;. This starts the code generation process behind the scenes. Copy the generated command and paste it into the Windsurf terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: set up rules for AI
&lt;/h3&gt;

&lt;p&gt;While you can start generating code right away, configuring AI rules helps produce code that better matches project standards:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;strong&amp;gt;.windsurfrules&amp;lt;/strong&amp;gt;&lt;/code&gt;: For project-specific customization in your workspace in Windsurf.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;strong&amp;gt;.builderrules&amp;lt;/strong&amp;gt;&lt;/code&gt;: To add custom instructions that will be automatically injected into the LLM prompt during code generation. Define anything from component naming conventions and state management patterns to error handling approaches and custom hook patterns.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;strong&amp;gt;.builderignore&amp;lt;/strong&amp;gt;&lt;/code&gt;: To exclude specific files or patterns from being included in the code generation process. This is especially useful for template files that shouldn't influence the generated code, legacy code that doesn't follow current standards, third-party code that might confuse the generation process, and test files or mock data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%2FTEMP%2F109e96ea21252b82d1e31b1b1b1f63aae2ee6009b7262745e0c6b253fa5e21d2%3FplaceholderIfAbsent%3Dtrue%26width%3D24" alt="exclamation" width="18" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.builderrules&lt;/code&gt; and &lt;code&gt;.builderignore&lt;/code&gt; are Visual Copilot-specific and won't affect Windsurf’s code generation&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: guide the code generation
&lt;/h3&gt;



&lt;p&gt;Tell the AI what you're building. For example: "This is a signup form for new users."&lt;/p&gt;

&lt;p&gt;Visual Copilot and Windsurf will then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analyze existing project files&lt;/li&gt;
&lt;li&gt;Read &lt;code&gt;.builderrules&lt;/code&gt;, &lt;code&gt;.builderignore&lt;/code&gt; and &lt;code&gt;.**windsurfrules**&lt;/code&gt; files to understand coding patterns&lt;/li&gt;
&lt;li&gt;Generate code matching the project's framework and styling choices (React with Tailwind CSS for example)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 5: make it better with Windsurf
&lt;/h3&gt;



&lt;p&gt;This is where Windsurf's AI capabilities truly shine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cascade&lt;/strong&gt;: Add more features to your code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chat&lt;/strong&gt; (⌘ + L): Ask questions about your code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Codeium Command&lt;/strong&gt; (⌘ + K): Make quick changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The real-time awareness feature means you won't need to repeatedly explain your context - Windsurf understands your actions as you make them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pro tips for better Figma to Windsurf results
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use Auto Layout in Figma&lt;/strong&gt;: When designing your components and layouts in Figma, always use Auto Layout. This helps Visual Copilot generate more accurate and responsive code that better matches your design intentions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage Cascade memories&lt;/strong&gt;: Use Windsurf's Cascade Memories to persist context across sessions. This helps maintain consistency in your code generation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pin important context&lt;/strong&gt;: For specific bits of code you want extra attention on, pin directories, files, repositories, or code context items as persistent context.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;Integrating Visual Copilot with Windsurf saves you from copying designs into code by hand. You also won't need to switch back and forth between design and code to check measurements or fix layout problems.&lt;/p&gt;

&lt;p&gt;Instead, your designs become working code in minutes. Visual Copilot creates the code, and Windsurf helps you fit it into your project perfectly.&lt;/p&gt;

&lt;p&gt;It's a workflow that frees you to focus on building features that delight your users—and shipping them faster than ever.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What frameworks are supported? Visual Copilot supports React, Vue, Svelte, Angular, and more, while Windsurf works with any language VS Code supports.&lt;/li&gt;
&lt;li&gt;Does this work with my existing codebase? Yes! Both tools are designed to integrate seamlessly with your existing projects. Windsurf keeps track of your code in real-time.&lt;/li&gt;
&lt;li&gt;What AI models are available? Windsurf gives everyone access to Llama 3.1 70B. Paid users get Llama 3.1 405B, GPT-4, and Claude 3.5 Sonnet (which can understand images).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you enjoyed this post, you might also like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-windsurf-vs-github-copilot" rel="noopener noreferrer"&gt;Cursor vs Windsurf vs GitHub Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/devin-vs-cursor" rel="noopener noreferrer"&gt;Devin vs Cursor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/react-ai-stack" rel="noopener noreferrer"&gt;React + AI Stack for 2025&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>windsurf</category>
      <category>figma</category>
      <category>ai</category>
    </item>
    <item>
      <title>Replace your JavaScript Animation Library with View Transitions</title>
      <dc:creator>Stefan Judis</dc:creator>
      <pubDate>Wed, 05 Feb 2025 14:14:28 +0000</pubDate>
      <link>https://dev.to/builderio/replace-your-javascript-animation-library-with-view-transitions-d9e</link>
      <guid>https://dev.to/builderio/replace-your-javascript-animation-library-with-view-transitions-d9e</guid>
      <description>&lt;p&gt;I've always wanted the web to win, full stop. When I compared the web experience to mobile apps, however, it always felt like the web was losing. After all these years, the web still feels like a collection of documents linked without delight or an excellent user experience. Don't get me wrong, with the CSS evolution in full swing; we got many new and useful features, but it was still missing an easy-to-use API to animate, move, and even morph elements into each other…&lt;/p&gt;

&lt;p&gt;Even simple animations like the ones below required wild and unmaintainable CSS hacks or heavy JavaScript animation libraries.&lt;/p&gt;



&lt;p&gt;For those rooting for the web, 2025 has now exciting news! Both Chrome and Safari shipped a new and fairly straightforward way to add animations and transitions to your sites — &lt;strong&gt;say “Hello” to the View Transitions API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let me show you how view transitions work by recreating this animation effect with a few freckles of modern web technology. A web technology that is probably the most significant web platform update in years.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Generating markup from your design&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Whenever I want to quickly sketch something out (like the code for this blog post), I reach for &lt;a href="https://www.builder.io/blog/figma-to-code-visual-copilot" rel="noopener noreferrer"&gt;Builder's Visual Copilot&lt;/a&gt;. Design something in Figma, import the design into Builder using &lt;a href="https://www.builder.io/c/docs/import-from-figma" rel="noopener noreferrer"&gt;the Figma plugin&lt;/a&gt;, and off you go.&lt;/p&gt;

&lt;p&gt;With a single command, you'll be ready to pull your codified design into your codebase.&lt;/p&gt;



&lt;p&gt;Pure HTML, React, and even Swift exports are available to give you a headstart. It's pretty sweet!&lt;/p&gt;

&lt;p&gt;But let's get to some animation magic.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The base setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To explain the view transition core concepts, we'll use a vanilla approach to rebuilding this animated navigation — HTML, CSS, and good old JavaScript to toggle an &lt;code&gt;active&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;That will be it; there won't be animation libraries or other external dependencies. All included concepts can be applied to sites built with or without frameworks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you're wondering how to apply view transitions to your React, Vue, or Angular app, you'll &lt;a href="https://developer.chrome.com/docs/web-platform/view-transitions/same-document#working_with_frameworks" rel="noopener noreferrer"&gt;find resources on web.dev&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, where do we get started?&lt;/p&gt;

&lt;p&gt;Here's the HTML we'll use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"active"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Projects&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing fancy — it's just a list of links.&lt;/p&gt;

&lt;p&gt;And here's some basic JavaScript to toggle the &lt;code&gt;active&lt;/code&gt; class on all the included navigation links on click.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allLinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;allLinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setActiveItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setActiveItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;allLinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;active&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;active&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CSS will be pretty common stuff, except for the background of the active link element. The active link’s background isn’t rendered on the link itself but rather a pseudo-element. We'll need this extra pseudo-element to animate and slide it around later on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nc"&gt;.active&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;inset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#6a11cb&lt;/span&gt; &lt;span class="m"&gt;0%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#2575fc&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a live preview of how the project looks so far:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/VYZgaeO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Getting started with JavaScript view transitions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;So, what are they — these view transitions? Here's what &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API" rel="noopener noreferrer"&gt;MDN has to say about them&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;View Transition API&lt;/strong&gt; provides a mechanism for easily creating animated transitions between different website views. This includes animating between DOM states in a single-page app (SPA), and animating the navigation between documents in a multi-page app (MPA).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;View transitions allow you to take screenshots of DOM elements, then modify the DOM and magically transition from the old view to the new DOM representation.&lt;/p&gt;

&lt;p&gt;In this article, we'll cover the animation between different DOM states triggered via JavaScript (the SPA mode), but we will cover cross-document transitions in the future here on the blog. Check the newsletter box in the footer if you want to catch the next article.&lt;/p&gt;

&lt;p&gt;But let's get started, and I'll explain the concepts along the way. At the core of view transitions is the &lt;code&gt;startViewTransition&lt;/code&gt; JavaScript method.&lt;/p&gt;

&lt;p&gt;Here's the getting-started example snippet from &lt;a href="https://developer.chrome.com/docs/web-platform/view-transitions/same-document" rel="noopener noreferrer"&gt;the view transitions web.dev guide&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Fallback for browsers that don't support this API:&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startViewTransition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;updateTheDOMSomehow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// With a View Transition:&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startViewTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;updateTheDOMSomehow&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To animate between DOM states, you pass a callback function to &lt;code&gt;startViewTransition&lt;/code&gt; that modifies the DOM. You could add new DOM nodes or add or remove classes; either way, the browser will transition between the old and new DOM states.&lt;/p&gt;

&lt;p&gt;A quick note about browser support: Safari and Chromium support the new API at the time of writing, and I recommend treating view transitions as a progressive enhancement. Chromium and Safari (90% global share) users will then see the new and fancy web. For me, that's good enough, and I bet the rest won't miss it.&lt;/p&gt;

&lt;p&gt;Luckily, view transitions support is easy to detect. If &lt;code&gt;document.startViewTransition&lt;/code&gt; is available on the &lt;code&gt;document&lt;/code&gt; object, you can use the API to create transitions and animations. If it's not, you update the DOM as usual, and people on older browsers or Firefox won't see smooth transitions. In my opinion, that's a good trade and better than loading tons of JavaScript for everybody.&lt;/p&gt;

&lt;p&gt;Let's add &lt;code&gt;startViewTransition&lt;/code&gt; to our example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allLinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;allLinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Fallback for browsers that don't support this API:&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startViewTransition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setActiveItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Update the DOM with a view transition&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startViewTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setActiveItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code is now similar to the initial example; the only change is that &lt;code&gt;setActiveItem&lt;/code&gt; is now called by &lt;code&gt;startViewTransition&lt;/code&gt; if the browser supports it.&lt;/p&gt;

&lt;p&gt;And look at this, with this minor tweak, we already see a cross-fade happening for the active element:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/OPLdXoE?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Pretty cool, right? But what's going on, and how does this work?&lt;/p&gt;

&lt;p&gt;The browser will attach new pseudo-elements to the DOM whenever you start a new view transition. You can see these elements in the Chrome dev tools while a view transition is happening.&lt;/p&gt;



&lt;p&gt;Above, you see Chrome's animation tooling (you can open it with &lt;code&gt;CMD+Shift+p&lt;/code&gt; and search for “animation”) that I use to debug the triggered view transition. Thanks to the animation tooling, we can see the view transition pseudo-elements in the DOM and even slow down the animations. Very handy!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;::view-transition-old()&lt;/code&gt; is a screenshot of the old DOM state whereas &lt;code&gt;::view-transition-new()&lt;/code&gt; is a &lt;strong&gt;live&lt;/strong&gt; representation of the new DOM state. The old DOM screenshot is then transitioned to the new live DOM presentation. By default, this is done with a fade and mix-blend transition. But what are we transitioning here?&lt;/p&gt;

&lt;p&gt;If you look closely, you see that by using &lt;code&gt;startViewTransition&lt;/code&gt;, the browser will take the root element (the &lt;code&gt;html&lt;/code&gt; element) take a screenshot of it, and fade to the newly updated HTML DOM state. Just like that? Yep, you can add cross-fade transitions to your sites with a JavaScript one-liner.&lt;/p&gt;

&lt;p&gt;That's fun, but why stop there? Let's build up our navigation component and animate more than the root element.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Use &lt;code&gt;view-transition-name&lt;/code&gt; to animate elements separately&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When we look at our target components from the beginning, we want to animate the active nav element separately. How can we achieve this?&lt;/p&gt;

&lt;p&gt;For these use cases, we can specify in CSS that we want to have another animation group with the &lt;code&gt;view-transition-name&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Move the active link into its own view transition layer */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nc"&gt;.active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;active-nav-elem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And look at this: this animation effect isn't quite what we're after, and it's not perfect yet (notice this small visual glitch), but it's quite impressive for a single line of CSS.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/pvzGErg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you inspect the DOM, you'll discover that there are more &lt;code&gt;view-transition-&lt;/code&gt; pseudo-elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fef9f096c61f941abb344afc90706391c%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fef9f096c61f941abb344afc90706391c%3Fwidth%3D705" alt="View transition pseudo-elements rendered in the DOM." width="705" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;View transition pseudo-elements rendered in the DOM.&lt;/p&gt;

&lt;p&gt;We still have the view transition elements for &lt;code&gt;root&lt;/code&gt;, but there are now also elements for our active link (&lt;code&gt;active-nav-elem&lt;/code&gt;), which was put into its own group by applying the &lt;code&gt;view-transition-name&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;::view-transition-group(active-nav-elem)&lt;/code&gt; transitions the elements’ positioning, transform, width, and height properties. Remember, it's a screenshot of the old active link and a live presentation of the new active link, and the browser transitions from one to the other. It doesn't matter that transitioning active links are completely different DOM nodes. The browser will just figure it out and visually morph one element into the other. Wild!&lt;/p&gt;

&lt;p&gt;What you see above is that the active link view transition is rendered above on top of a cross-fade root view transition. That's why it looks like links are fading away under the active element, but, in practice, it's the entire root element doing a cross-fade. Pretty cool, right?&lt;/p&gt;

&lt;p&gt;Next, let's fix this visible glitch in the active element transition.&lt;/p&gt;

&lt;p&gt;The problem is that the transition group tries to transition two elements with different dimensions and aspect ratios. The “Home” link is smaller than the “Projects” link.&lt;/p&gt;

&lt;p&gt;To smoothen the transition, we can target the two pseudo-elements in CSS, tweak the animation, and define that they both should match in height while still doing the cross-fade.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Apply the same height to ease the view transition */&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-old&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;active-nav-elem&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-new&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;active-nav-elem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isn't this cool?&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/azoXmaE?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Even though it looks pretty fancy already, this isn't the effect we are looking for. How could we make the highlighted gradient box slide under the text?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Apply view transitions to pseudo-elements&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Do you remember that the background gradient was done with a &lt;code&gt;::before&lt;/code&gt; pseudo-element instead of setting a background on the active link? Now that we know about the &lt;code&gt;view-transition-name&lt;/code&gt; property, we can animate the pseudo-element instead of the entire link.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Move the background to its own view transition layer */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nc"&gt;.active&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;active-nav-elem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And again, this doesn't look too bad for such a tiny change. Does it?&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/GgKzjYa?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But the background view transition is now covering the text fragments. How can we move the text on top of the ongoing background transition?&lt;/p&gt;

&lt;p&gt;We can put all the links into their own view transition layers and control all the view transition pseudo-elements with a &lt;code&gt;z-index&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;This could be done right in CSS…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Move all the links into their own view transition layer */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nav-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nav-2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nav-3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…and this kind of works, but if you use a templating engine or a framework, you're better off defining the view transition names in HTML with inline styles. It's more maintainable and will guarantee that you don't need to touch your CSS if you update the number of navigation items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"active"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"view-transition-name: nav-1;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"view-transition-name: nav-2;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Projects&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"view-transition-name: nav-3;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks better, but still not quite right.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/emOxdXE?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;When navigating forward, the background is placed under the text fragments, but you still see the background covering the text when going backward. Why's that?&lt;/p&gt;

&lt;p&gt;We didn't apply the &lt;code&gt;z-index&lt;/code&gt; to all our view transitions yet!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Applying &lt;code&gt;z-index&lt;/code&gt; to separate view transitions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;By default, view transitions are stacked on top of each other depending on where they are defined in the DOM. If the active link pseudo-element is first in our navigation, the view transition pseudo-elements look as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fc18462ba955b4713b1f343e2b849f5cc%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fc18462ba955b4713b1f343e2b849f5cc%3Fwidth%3D705" alt="View transition pseudo-lements highlight in DevTools. The ::view-transition-group(active-nav-elem) is highlighted on third position." width="705" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;View transition pseudo-lements highlight in DevTools. The &lt;code&gt;::view-transition-group(active-nav-elem)&lt;/code&gt; is highlighted on third position.&lt;/p&gt;

&lt;p&gt;We have the first text link (&lt;code&gt;nav-1&lt;/code&gt;) and then the pseudo-element on top of it. And going on, the &lt;code&gt;nav-2&lt;/code&gt; and &lt;code&gt;nav-3&lt;/code&gt; text elements are on top of the background pseudo-element.&lt;/p&gt;

&lt;p&gt;If we transition from the third link being active, the &lt;code&gt;active-nav-elem&lt;/code&gt; transition layer comes last and covers all the text links when it transitions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fd37f9457a6b7438996d0c63edac2103b%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Fd37f9457a6b7438996d0c63edac2103b%3Fwidth%3D705" alt="View transition pseudo-lements highlight in DevTools. The ::view-transition-group(active-nav-elem) is highlighted on last position." width="705" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;View transition pseudo-lements highlight in DevTools. The &lt;code&gt;::view-transition-group(active-nav-elem)&lt;/code&gt; is highlighted on last position.&lt;/p&gt;

&lt;p&gt;We need to apply a &lt;code&gt;z-index&lt;/code&gt; to our text layers to fix this. But how?&lt;/p&gt;

&lt;p&gt;To apply custom styles like the &lt;code&gt;z-index&lt;/code&gt; to the transition layers, we can target the transition groups in CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Stack the text over the animated background */&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;nav-1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;nav-2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;nav-3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But hold on, isn't this the problem of having a hardcoded number of items in our CSS? That's correct, and there's a solution, but I wouldn't recommend using it in production yet.&lt;/p&gt;

&lt;p&gt;You could rely on the &lt;code&gt;view-transition-class&lt;/code&gt; property to target multiple view transition pseudo-elements, but &lt;a href="https://caniuse.com/mdn-css_properties_view-transition-class" rel="noopener noreferrer"&gt;its browser support isn't great yet&lt;/a&gt; (Chromium and recent Safari). MDN doesn't even have a docs page for it.&lt;/p&gt;

&lt;p&gt;View transition classes work similarly to “normal” classes. Give multiple elements the same view transition class and target the resulting layers with the view-transition pseudo-element selectors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Define a view transition class to target multiple view transition layers */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;view-transition-class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nav-item&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Apply styles to multiple view transition layers */&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.nav-item&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're on Chromium or a recent Safari, here's the fixed stacking context with cutting-edge CSS.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/dPbapLQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;So, as of now, I recommend hardcoding the view transition layers until &lt;code&gt;view-transition-class&lt;/code&gt; has better browser support. It’s not pretty, but it's not too bad, either. &lt;a href="https://frontendmasters.com/blog/view-transitions-staggering/" rel="noopener noreferrer"&gt;This article is excellent if you want to read more about view transition classes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There's one last bit of fanciness I want to add, though!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Controlling view transitions with custom easing functions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The background pseudo-element is now smoothly sliding below all the text links and it's looking pretty good, but I think it could look a bit more fun. Let's make it bounce and apply some custom easing functions to the transition group, that's wrapping the background element.&lt;/p&gt;

&lt;p&gt;Remember, view transitions are all about CSS; we can go in, apply a custom easing function, and even control the time of our background element transition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--bounce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.271&lt;/span&gt; &lt;span class="m"&gt;8.8%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.542&lt;/span&gt; &lt;span class="m"&gt;19.9%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.837&lt;/span&gt; &lt;span class="m"&gt;34.2%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;44.7%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.943&lt;/span&gt; &lt;span class="m"&gt;51.1%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.925&lt;/span&gt; &lt;span class="m"&gt;57.5%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.937&lt;/span&gt; &lt;span class="m"&gt;63.1%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;77.4%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;0.991&lt;/span&gt; &lt;span class="m"&gt;84.2%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Tweak the active background animation */&lt;/span&gt;
&lt;span class="nd"&gt;::view-transition-group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;active-nav-elem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-timing-function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--bounce&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;animation-duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.375s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you haven't seen &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function/linear" rel="noopener noreferrer"&gt;the &lt;code&gt;linear()&lt;/code&gt; easing function&lt;/a&gt; yet, it allows us to create bouncy effects like the one below. You probably don't want to code these by hand, however, which is why I recommend using &lt;a href="https://easingwizard.com/" rel="noopener noreferrer"&gt;the Easing Wizard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And now, look at the final result!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/stefanjudis/embed/WbePaKO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I don't know about you, but I'm pretty excited about all this!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Quick side note: if you now go ahead and create animations heavily moving DOM elements around, be a good web citizen, and allow people to opt-out by &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion" rel="noopener noreferrer"&gt;using &lt;code&gt;@media (prefers-reduced-motion) {}&lt;/code&gt;&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;View transitions allow us to finally push the web to the next level and I'm so there for it!&lt;/p&gt;

&lt;p&gt;I hope this small example shows the power of the new View Transitions API. We needed roughly 50 lines of CSS to build something that would usually require thousands of lines of JavaScript locking your CPU. The future is bright (and animated).&lt;/p&gt;

&lt;p&gt;If you want to learn more about view transitions, let us know in the comments, &lt;a href="//mailto:stefanjudis@gmail.com"&gt;shoot me an email&lt;/a&gt;, or tag us on social. If we get great feedback, we'll publish more articles on the matter soon. Oh, and make sure to subscribe to our newsletter below if you want to catch more articles on this topic.&lt;/p&gt;

&lt;p&gt;Until then — have fun dropping some heavy animation libraries from your code bases!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/prAHP9miQDY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Written by&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;span&gt;Stefan Judis&lt;/span&gt;
&lt;/h2&gt;

&lt;p&gt;Stefan loves getting into web performance, new technologies, and accessibility, sends out &lt;a href="https://webweekly.email/" rel="noopener noreferrer"&gt;a weekly web development newsletter&lt;/a&gt; and enjoys sharing &lt;a href="https://www.stefanjudis.com/today-i-learned/" rel="noopener noreferrer"&gt;nerdy discoveries on his blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>css</category>
      <category>animation</category>
    </item>
    <item>
      <title>Figma to Code with Cursor and Visual Copilot</title>
      <dc:creator>Vishwas</dc:creator>
      <pubDate>Mon, 03 Feb 2025 19:21:39 +0000</pubDate>
      <link>https://dev.to/builderio/figma-to-code-with-cursor-and-visual-copilot-14dh</link>
      <guid>https://dev.to/builderio/figma-to-code-with-cursor-and-visual-copilot-14dh</guid>
      <description>&lt;p&gt;If you’ve ever converted a Figma design into a functional interface, you know just how tedious that process can be.&lt;/p&gt;

&lt;p&gt;Every pixel-perfect design detail—fonts, spacing, responsive layouts, and interactions — has to be painstakingly recreated in HTML, CSS, and JavaScript (or whatever your stack might be). It’s like retyping a book you already wrote, just so it can be “officially” published.&lt;/p&gt;

&lt;p&gt;The good news is that we’re finally at a point where that level of hand-holding is about to disappear. The &lt;strong&gt;Cursor&lt;/strong&gt; and &lt;strong&gt;Visual Copilot&lt;/strong&gt; integration eliminates this manual design-to-code work, letting you focus on what truly matters: building features and delivering great products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cursor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.cursor.com/" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt; is like having a senior developer looking over your shoulder 24/7. It's an AI-powered code editor built on top of &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; that understands your entire codebase and helps you write, refactor, and optimize code faster than ever.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Visual Copilot&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.figma.com/community/plugin/747985167520967365/builder-io-ai-powered-figma-to-code-react-vue-tailwind-more" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; is &lt;a href="https://www.builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt;’s AI-powered Figma to code toolchain that leverages AI models to convert Figma designs into React, Vue, Svelte, Angular, HTML, etc code in real-time. It can even reuse your existing components in the output and use any styling library or design system you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up your workflow
&lt;/h2&gt;

&lt;p&gt;Getting started is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the &lt;a href="https://www.figma.com/community/plugin/747985167520967365" rel="noopener noreferrer"&gt;Visual Copilot plugin&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download &lt;a href="https://www.cursor.com/" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Convert Figma design to code
&lt;/h2&gt;

&lt;p&gt;The beauty here is that Visual Copilot supports all major frameworks (React, Vue, Svelte, Angular) and styling solutions (Tailwind CSS, Emotion, Styled Components). Whether you're building a simple landing page or a complex application, Visual Copilot can generate the code you need in your preferred tech stack. Let's walk through the process:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: launch the Visual Copilot Figma plugin
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F295acb858f474d979502f97241280420%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F295acb858f474d979502f97241280420%3Fwidth%3D705" alt="Figma plugin search interface showing Builder.io AI-Powered Figma to Code plugin in the Plugins &amp;amp; widgets section." width="705" height="705"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figma plugin search interface showing &lt;a href="http://builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt; AI-Powered Figma to Code plugin in the Plugins &amp;amp; widgets section.&lt;/p&gt;

&lt;p&gt;In your Figma file, open the Actions menu from the toolbar, then click the Plugins &amp;amp; widgets tab. Search for “Builder.io AI-powered Figma to Code” plugin and run it.&lt;/p&gt;

&lt;p&gt;You can also &lt;a href="https://www.figma.com/community/plugin/747985167520967365" rel="noopener noreferrer"&gt;try the plugin&lt;/a&gt; from the Figma community page directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: export to code
&lt;/h3&gt;



&lt;p&gt;Select the design you want to convert. You’ll get a preview in the plugin. If you’re satisfied with your selection, click the &lt;strong&gt;Export to Code&lt;/strong&gt; button. This starts the code generation process behind the scenes. Copy the generated command and paste it into your Cursor terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: configure rules for AI
&lt;/h3&gt;

&lt;p&gt;While you can start generating code right away, configuring rules for AI will help produce code that better matches your project's standards:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.cursorrules&lt;/code&gt;&lt;/strong&gt;: Configure this file to maintain consistent coding patterns across your project. This helps Cursor understand your coding standards and practices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.builderrules&lt;/code&gt;&lt;/strong&gt;: Use this to add custom instructions that will be automatically injected into the LLM prompt during code generation. You can define anything from component naming conventions and state management patterns to error handling approaches and custom hook patterns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.builderignore&lt;/code&gt;&lt;/strong&gt;: Use this file to exclude specific files or patterns from being included in the code generation process. This is especially useful for template files that shouldn't influence the generated code, legacy code that doesn't follow current standards, third-party code that might confuse the generation process, and test files or mock data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While optional, setting up these configuration files is highly recommended for better code generation results. Note that &lt;code&gt;.builderrules&lt;/code&gt; and &lt;code&gt;.builderignore&lt;/code&gt; are Visual Copilot-specific and won't affect Cursor's code generation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: guide the code generation
&lt;/h3&gt;



&lt;p&gt;Here's where the magic really happens — tell the AI how your design fits into your project. Something like "a new registration card component for our auth flow" is all it takes.&lt;/p&gt;

&lt;p&gt;Together, Visual Copilot and Cursor will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analyze your existing project files.&lt;/li&gt;
&lt;li&gt;Read your &lt;code&gt;.builderrules&lt;/code&gt;, &lt;code&gt;.builderignore&lt;/code&gt; and &lt;code&gt;.cursorrules&lt;/code&gt; files to understand your coding patterns.&lt;/li&gt;
&lt;li&gt;Generate code that matches your project's framework and styling choices (like React with Tailwind CSS).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 5: Enhance with Cursor
&lt;/h3&gt;

&lt;p&gt;This is where &lt;a href="https://www.builder.io/blog/cursor-advanced-features" rel="noopener noreferrer"&gt;Cursor's AI superpowers&lt;/a&gt; come into play. Open your newly generated code in Cursor and use its features to take things to the next level:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;⌘ K&lt;/code&gt; to refactor and optimize the generated code.&lt;/li&gt;
&lt;li&gt;Leverage &lt;strong&gt;Chat&lt;/strong&gt; to get instant answers about the code structure.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Composer&lt;/strong&gt; for larger architectural changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While Visual Copilot generates responsive layouts, you can use Cursor to ensure your responsive implementation works flawlessly across all screen sizes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pro tips for better &lt;strong&gt;Figma to Cursor&lt;/strong&gt; results
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use Auto Layout in Figma&lt;/strong&gt;: When designing your components and layouts in Figma, always use Auto Layout. This helps Visual Copilot generate more accurate and responsive code that better matches your design intentions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep configuration files updated&lt;/strong&gt;: Regularly update your &lt;code&gt;.cursorrules&lt;/code&gt;, &lt;code&gt;.builderrules&lt;/code&gt;, and &lt;code&gt;.builderignore&lt;/code&gt; files as your project evolves. This ensures the generated code continues to align with your team's latest standards and practices.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By integrating Visual Copilot with Cursor, you'll eliminate the mind-numbing DOM manipulation and pixel-pushing that eats up your dev time. No more context-switching between Figma and your IDE to grab exact measurements, or debugging mysterious padding issues that make your implementation drift from the design specs.&lt;/p&gt;

&lt;p&gt;Instead, you can turn designs into production-ready code with just a few clicks. Visual Copilot handles the heavy lifting of code generation, while Cursor's AI capabilities help you refine, optimize, and integrate that code seamlessly into your project.&lt;/p&gt;

&lt;p&gt;It’s a workflow that frees you to focus on building features that delight your users—and shipping them faster than ever.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What frameworks are supported? Visual Copilot supports React, Vue, Svelte, Angular, and more, while Cursor works with any language VS Code supports.&lt;/li&gt;
&lt;li&gt;Does this work with my existing codebase? Yes! Both tools are designed to integrate seamlessly with your existing projects. You'll find it incredibly helpful in streamlining your workflow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you enjoyed this post, you might also like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/cursor-vs-github-copilot" rel="noopener noreferrer"&gt;Cursor vs GitHub Copilot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/devin-vs-cursor" rel="noopener noreferrer"&gt;Devin vs Cursor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/react-ai-stack" rel="noopener noreferrer"&gt;React + AI Stack for 2025&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>figma</category>
      <category>webdev</category>
      <category>design</category>
      <category>ai</category>
    </item>
    <item>
      <title>Building High-Performance React Components with AI Assistance</title>
      <dc:creator>Luke Stahl</dc:creator>
      <pubDate>Wed, 29 Jan 2025 16:10:19 +0000</pubDate>
      <link>https://dev.to/builderio/building-high-performance-react-components-with-ai-assistance-fbj</link>
      <guid>https://dev.to/builderio/building-high-performance-react-components-with-ai-assistance-fbj</guid>
      <description>&lt;p&gt;React components are the core of modern web apps. As projects grow, so do the challenges of writing efficient, maintainable code. &lt;a href="https://www.builder.io/blog/best-ai-coding-tools" rel="noopener noreferrer"&gt;AI tools&lt;/a&gt; offer new ways to tackle these challenges. This post covers practical ways to improve component architecture, performance, state management, and testing with AI assistance. We'll go over real code examples and specific techniques you can use in your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Component architecture: keeping things tidy
&lt;/h2&gt;

&lt;p&gt;Keeping components small, focused, and reusable is a constant theme. But how do we actually do that in practice? Here's what I've found works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with a clear purpose for each component. If you can't explain it in a sentence, it might be doing too much.&lt;/li&gt;
&lt;li&gt;Use AI to help spot patterns in your code. I've been using &lt;a href="https://www.cursor.com/" rel="noopener noreferrer"&gt;Cursor&lt;/a&gt;, and it's pretty good at suggesting ways to break down complex components.&lt;/li&gt;
&lt;li&gt;Don't be afraid to &lt;a href="https://www.builder.io/blog/good-vs-bad-refactoring" rel="noopener noreferrer"&gt;refactor&lt;/a&gt;. AI can also help here, suggesting common patterns seen in other codebases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a quick example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;comments&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Lots of logic here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// After&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserInfo&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserPosts&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserComments&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's how we might visualize this breakdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Ffff5521200214b7d9fc476e39703d7ce%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252Ffff5521200214b7d9fc476e39703d7ce%3Fwidth%3D705" alt="UserProfile - UserInfo - UserPosts - UserComments" width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This structure keeps each component focused on a single responsibility, making our code easier to maintain and test.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Performance optimization: speed things up
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React's&lt;/a&gt; pretty fast out of the box, but there's always room for improvement. Here are some suggestions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://react.dev/reference/react/memo" rel="noopener noreferrer"&gt;React.memo&lt;/a&gt; for components that render often but don't change much.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://react.dev/reference/react/lazy" rel="noopener noreferrer"&gt;Lazy load&lt;/a&gt; components that aren't immediately visible.&lt;/li&gt;
&lt;li&gt;Be smart about your re-renders, useCallback and useMemo can help.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or you could just use &lt;a href="https://react.dev/blog/2023/05/03/react-compiler" rel="noopener noreferrer"&gt;React Compiler&lt;/a&gt; to automatically optimize your React code at build time. It can eliminate unnecessary re-renders and reduce bundle size. Test it out at the &lt;a href="https://playground.react.dev/" rel="noopener noreferrer"&gt;React Compiler Playground&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's a diagram showing how React Complier can prevent unnecessary re-renders:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3332de52544f4c089c4a8decb7524e2f%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3332de52544f4c089c4a8decb7524e2f%3Fwidth%3D705" alt="React code - react compiler - optimization process - reduce bundle size - optimized React code - build process - optimized bundle" width="705" height="705"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This diagram shows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;React code enters React Compiler.&lt;/li&gt;
&lt;li&gt;The compiler optimizes by reducing re-renders, shrinking bundle size, and streamlining the component tree.&lt;/li&gt;
&lt;li&gt;Optimized code is processed and bundled.&lt;/li&gt;
&lt;li&gt;Result: An efficient, deployment-ready bundle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AI can help spot potential performance issues. Cursor is my go-to again for reviewing my code and suggesting optimizations.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. State management: keeping things in check
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt;, &lt;a href="https://mobx.js.org/README.html" rel="noopener noreferrer"&gt;MobX&lt;/a&gt;, and &lt;a href="https://recoiljs.org/" rel="noopener noreferrer"&gt;Recoil&lt;/a&gt; are some examples here but there are more. Here's an example of what can work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with local state. You'd be surprised how far you can get with just &lt;code&gt;useState&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For more complex state needs, consider lightweight libraries like &lt;a href="https://jotai.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Jotai&lt;/strong&gt;&lt;/a&gt; or &lt;a href="https://github.com/pmndrs/zustand" rel="noopener noreferrer"&gt;&lt;strong&gt;Zustand&lt;/strong&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Only reach for heavy-duty state management libraries when your app truly requires it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a diagram showing different levels of state management:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6805480e26cc49e6ba686e63d72cc128%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F6805480e26cc49e6ba686e63d72cc128%3Fwidth%3D705" alt="App state - local component state - Lightweight state library - Full state management library" width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AI can help you decide which approach to use. You can describe your app structure to an AI assistant and ask for state management suggestions. It might not always give you the perfect answer, but it can offer fresh perspectives and ideas you hadn't considered.&lt;/p&gt;

&lt;p&gt;The goal is to keep your state management as simple as possible while meeting your app's needs. Then, you can scale your solution as your app grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Testing: because we all should
&lt;/h2&gt;

&lt;p&gt;Testing React components can be a pain, but it's worth it. Here's a good approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://jestjs.io/" rel="noopener noreferrer"&gt;Jest&lt;/a&gt;/&lt;a href="https://vitest.dev/" rel="noopener noreferrer"&gt;Vitest&lt;/a&gt; and &lt;a href="https://testing-library.com/docs/react-testing-library/intro/" rel="noopener noreferrer"&gt;React Testing Library&lt;/a&gt;. They work well together.&lt;/li&gt;
&lt;li&gt;Test behavior, not implementation. Your tests should care about what the user experiences, not how you've structured your components.&lt;/li&gt;
&lt;li&gt;Use AI to help generate test cases, whether that is ChatGPT, Claude, or any other.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;renders user name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserProfile&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBeInTheDocument&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's a diagram of a typical test workflow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5086dcfa24ee45e28de82720facc2b30%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F5086dcfa24ee45e28de82720facc2b30%3Fwidth%3D705" alt="Write component - write tests - run tests - fix issues - refactor/optimize" width="705" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Real-world example: putting it all together
&lt;/h2&gt;

&lt;p&gt;Let's say we're building a chat application. Here's how we might apply these principles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;memo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ChatWindow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ChatWindow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;UserList&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./UserList&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Chat&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSelectedUser&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleUserSelect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setSelectedUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"chat-app"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserList&lt;/span&gt; &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onSelectUser&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleUserSelect&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChatWindow&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Chat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a diagram of how this component structure might look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3a35032dcaad438696dcc17e199ca299%3Fwidth%3D705" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.builder.io%2Fapi%2Fv1%2Fimage%2Fassets%252FYJIGb4i01jvw0SRdL5Bt%252F3a35032dcaad438696dcc17e199ca299%3Fwidth%3D705" alt="Chat application - UserList - ChatWindow " width="705" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we're using &lt;code&gt;memo&lt;/code&gt; to optimize re-renders, &lt;code&gt;useState&lt;/code&gt; for local state management, and &lt;code&gt;useCallback&lt;/code&gt; to memoize our event handler. We've also split our UI into smaller, focused components.&lt;/p&gt;

&lt;p&gt;Here is what's happening:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We're using &lt;code&gt;memo&lt;/code&gt; to wrap our Chat component. This ensures that the component only re-renders if its props change.&lt;/li&gt;
&lt;li&gt;We're using &lt;code&gt;useState&lt;/code&gt; to manage the selected user state locally within the Chat component. This is a good example of starting with local state before reaching for more complex state management solutions.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;handleUserSelect&lt;/code&gt; function is wrapped with &lt;code&gt;useCallback&lt;/code&gt;. This memoizes the function, preventing unnecessary re-renders of child components that receive this function as a prop.&lt;/li&gt;
&lt;li&gt;We've split the UI into two main components: &lt;code&gt;UserList&lt;/code&gt; and &lt;code&gt;ChatWindow&lt;/code&gt;. This separation of concerns makes our code more maintainable and easier to test.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;ChatWindow&lt;/code&gt; is only rendered when a user is selected, improving performance by not rendering unnecessary components.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This structure allows for easy testing and maintenance. For example, we could easily write tests for the &lt;code&gt;UserList&lt;/code&gt; and &lt;code&gt;ChatWindow&lt;/code&gt; components in isolation, as well as integration tests for the Chat component.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Builder.io's Visual Copilot: AI-assisted React development&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.builder.io/" rel="noopener noreferrer"&gt;Builder.io&lt;/a&gt; has developed an AI tool to enhance React development workflows. Here's what &lt;a href="https://www.builder.io/m/design-to-code" rel="noopener noreferrer"&gt;Visual Copilot&lt;/a&gt; offers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AI component generation&lt;/strong&gt;: creates React component structures adhering to best practices, reducing setup time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated performance optimization&lt;/strong&gt;: analyzes components and applies performance improvements like code splitting and lazy loading without manual intervention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;State management recommendations&lt;/strong&gt;: evaluates application complexity and suggests appropriate state management solutions based on the project's needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI-driven test generation&lt;/strong&gt;: automatically generates test cases, including edge case scenarios, for Jest and react-testing-library.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context-aware code suggestions&lt;/strong&gt;: offers inline suggestions for React patterns and best practices as you code, improving efficiency and code quality.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visual Copilot aims to reduce repetitive tasks in React development, so developers can focus more on solving unique problems and creating effective user interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;The best code is often the most straightforward. Don't over-optimize, and always consider the readability and maintainability of your code.&lt;/p&gt;

&lt;p&gt;AI can be a powerful tool in your React development toolkit. It can help you spot patterns, suggest optimizations, and even generate boilerplate code.&lt;/p&gt;

&lt;p&gt;As you're building your next React app, try incorporating some of these techniques and see how they work for you.&lt;/p&gt;

&lt;p&gt;If you enjoyed this post, you might also like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/convert-figma-to-react-code" rel="noopener noreferrer"&gt;Figma to React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/react-component-library" rel="noopener noreferrer"&gt;React UI Component Libraries in 2025&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.builder.io/blog/react-ai-stack" rel="noopener noreferrer"&gt;React + AI Stack for 2025&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>ai</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
