Learn why Gartner just named Builder a Cool Vendor

Announcing Visual Copilot - Figma to production in half the time

Builder.io logo
Contact Sales
Contact Sales

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

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

Theme Studio for Shopify

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

Resources

Blog

Get StartedLogin

‹ Back to blog

AI

50+ ChatGPT Prompts for Web Developers

May 8, 2023

Written By Vishwas Gopinath

If you're tired of tedious and repetitive coding tasks and want to optimize your efficiency, you're in the right place. With the power of ChatGPT, you can streamline your workflow, reduce errors, and even gain insights on improving your code.

In this blog post, we'll provide you with over 50 prompts and strategies that will help you speed up your web development workflow using ChatGPT. From learning concepts as a beginner to preparing for interviews, you'll find everything you need to make the most of AI as a web developer.

But first, it's important to understand ChatGPT's limitations. Although it's a powerful tool, ChatGPT can't substitute your own knowledge and skills. You should also fact-check any research it does for you, as ChatGPT can't verify facts. Furthermore, its training data is only up to 2021, so it may not be aware of current trends or events. With those caveats in mind, let's dive into the exciting world of AI-powered web development!

You can run all the prompts on https://chatgpt.com/

Code generation

ChatGPT can generate code for a variety of web development tasks, freeing up your time and helping you be more efficient. It can help you generate semantic HTML and CSS code, JavaScript functions, and even database queries.

Prompt: Generate a semantic and accessible HTML and (framework) CSS [UI component] consisting of [component parts]. The [component parts] should be [layout].

Example: Generate a semantic HTML and Tailwind CSS "Contact Support" form consisting of the user's name, email, issue type, and message. The form elements should be stacked vertically and placed inside a card.

Prompt: Write a JavaScript function. It accepts [input] and returns [output].

Example: Write a JavaScript function. It accepts a full name as input and returns avatar letters.

Prompt: Write a/ an [framework] API for [functionality]. It should make use of [database].

Example: Write an Express.js API to fetch the current user's profile information. It should make use of MongoDB.

Prompt: The database has [comma-separated table names]. Write a [database] query to fetch [requirement].

Example: The database has students and course tables. Write a PostgreSQL query to fetch a list of students who are enrolled in at least 3 courses.

Code completion

With the power of AI, ChatGPT can also suggest code completions that match your context and style.

Prompt: Complete the code [code snippet]

Example: Complete the code:

const animals = ["dogs", "cats", "birds", "fish"];
let animal = animals[Math.floor(Math.random() * animals.length)];

switch (animal) {
  case "dogs":
    console.log(
      "Dogs are wonderful companions that bring joy and loyalty into our lives. Their wagging tails and wet noses never fail to make us smile."
    );
    break;
}

It is generally a good idea to end your prompt with a colon and paste your code block into a new line. Delimiting code blocks with triple backticks ```[code]``` or tripe quotes """[code]""" is also a good option.

Code conversion

As a developer, you might have to work with code that's written in different languages or frameworks. With ChatGPT, you can easily convert code snippets from one language or framework to another.

Prompt: Convert the below code snippet from [language/ framework] to [language/ framework]: [code snippet]

Example: Convert the below code snippet from JavaScript to TypeScript

function nonRepeatingWords(str1, str2) {
  const map = new Map();
  const res = [];
  // Concatenate the strings
  const str = str1 + " " + str2;
  // Count the occurrence of each word
  str.split(" ").forEach((word) => {
    map.has(word) ? map.set(word, map.get(word) + 1) : map.set(word, 1);
  });
  // Select words which occur only once
  for (let [key, val] of map) {
    if (val === 1) {
      res.push(key);
    }
  }
  return res;
}

Prompt: Convert the below code using [CSS framework] to use [CSS framework]: [code snippet]

Example: Convert the below code using Bootstrap to use Tailwind CSS: [code snippet]

Code explanation

ChatGPT can help you understand code by providing an explanation or answering specific questions about it. This can be especially useful when working with code written by others or when trying to understand complex pieces of code.

Prompt: Explain the following [language] snippet of code: [code block]

Prompt: What does this code do: [accepted answer code from stack overflow]

Code review

Code review is an essential aspect of software development, and it can often be difficult to catch every potential issue when you're working alone. With the help of ChatGPT, you can identify code smells and security vulnerabilities in your code to make it more efficient and secure.

Prompt: Review the following [language] code for code smells and suggest improvements: [code block]

Prompt: Identify any security vulnerabilities in the following code: [code snippet]

Code refactor

Have you ever written a //todo: refactor this code comment and never got to it? ChatGPT can help reduce that by suggesting ways to refactor and improve your code without spending too much time or effort.

Prompt: Refactor the given [language] code to improve its error handling and resilience: [code block]

Prompt: Refactor the given [language] code to make it more modular: [code block]

Prompt: Refactor the given [language] code to improve performance: [code block]

Prompt: Refactor the below component code to be responsive across mobile, tablet, and desktop screens: [code block]

Prompt: Suggest descriptive and meaningful names for variables and functions, making it easier to understand the purpose of each element in your code: [code snippet]

Prompt: Suggest ways to simplify complex conditionals and make them easier to read and understand: [code snippet]

Bug detection and fixing

As developers, we know that it's not always easy to catch all the bugs in our code. However, with the help of ChatGPT prompts, we can easily identify and resolve those pesky bugs that might be causing issues.

Prompt: Find any bugs in the following code: [code snippet]

Prompt: I am getting the error [error] from the following snippet of code: [code snippet]. How can I fix it?

System design and architecture

ChatGPT can provide valuable insights and recommendations on how to design a system using a specific technology stack or contrast the design and architecture with different technology stacks. Whether you're building a web application, a mobile app, or a distributed system, ChatGPT can help you design a scalable, reliable, and maintainable architecture that meets your needs.

Prompt: You are an expert at system design and architecture. Tell me how to design a [system]. The technology stack is [comma-separated list of technologies].

Example: You are an expert at system design and architecture. Tell me how to design a hotel reservation system. The technology stack is Next.js and Firebase.

Prompt: Contrast the design and architecture with [comma-separated list of technologies] as the technology stack.

Example: Contrast the design and architecture with React and Supabase as the technology stack.

Search Engine Optimization

ChatGPT can provide you with tips and best practices to optimize your website for search engines.

Prompt: How to improve SEO for a landing page?

Prompt: Give an example <head> section of the HTML code that is optimized for Search Engine Optimization (SEO) for a [website]

Example: Give an example <head> section of the HTML code that is optimized for Search Engine Optimization (SEO) for a social networking site for athletes

Mock data generation

Whether it's for testing or demonstration purposes, having realistic and representative data is crucial. ChatGPT can help you quickly generate mock data for various domains and formats.

Prompt: Generate a sample [data format] of [number] [entity] for a [domain]

Example: Generate a sample JSON of 5 products for a clothing e-commerce site

Prompt: You can also enter prompts after every response for more fine-grained control

  1. Give me a list of [number] fields for [entity] on an e-commerce site
  2. Add an “id” field that will be unique to each [entity]. Replace [existing field] with [new field]
  3. Generate a sample [data format] of [number] such [entity] with realistic values

Testing

ChatGPT can assist you in writing unit tests, generating a list of test cases, and choosing a suitable testing framework or library.

Prompt: Write unit tests for the following [library/ framework] component [component code] using [testing framework/ library]

Prompt: Generate a list of test cases to manually test user registration in a web/ mobile application.

Prompt: What testing frameworks or libraries should I choose for a React Native app?

Documentation

Whether you're working on a solo project or a team project, good documentation can save you time and prevent headaches down the line.

Prompt: Write comments for the code below: [code snippet]

Prompt: Write JSDoc comments for the below JavaScript function: [code snippet]

Shell commands

As a developer, you’re not limited to only writing code. ChatGPT can assist with shell commands and version control using Git

Prompt: Write a shell command to [requirement]

Example: Write a shell command to delete all files with the extension '.log' in the 'logs' folder

Prompt: Write a git command to [requirement]

Example: Write a git command to undo the previous commit

Prompt: Explain the following command [command]

Example: Explain the following command [git switch -c feat/qwik-loaders]

Regular expressions

With ChatGPT, you can understand complex regular expressions and generate ones that match specific patterns in text.

Prompt: Explain this regular expression: [regex]

Example: Explain this regular expression in JavaScript: const regex = /^[A-Za-z0–9._%+-]+@[A-Za-z0–9.-]+\\.[A-Za-z]{2,}$/;

Prompt: Your role is to generate regular expressions that match specific patterns in text. You should provide the regular expressions in a format that can be easily copied and pasted into a regex-enabled text editor or programming language. Generate a regular expression that matches [text].

Content

With ChatGPT, you can generate content for a variety of purposes, tailored to your specific needs.

Prompt: Generate a list of frequently asked questions for an e-commerce site

Prompt: Generate content for a course landing page. The course is "[course title]". It should include at the least, sections on what the course is, who the primary audience is, how they will benefit, the course sections and structure, the method of teaching, about the author, and a pricing section. For the pricing section, provide three tiers for the user to choose from.

Résumés and cover letters

Crafting a compelling and polished résumé and cover letter can be a daunting task, but with the help of ChatGPT, it doesn't have to be. ChatGPT will adhere closely to any character or word limits as well.

Prompt: Write a LinkedIn about section using my résumé: [résumé]. Use the keywords [comma-separated keywords]. Write in the first person and use a friendly tone of voice. Do not exceed 2,600 characters.

Prompt: I want you to act as a cover letter writer. I will provide you with my résumé, and you will generate a cover letter to complement it. I want the cover letter to have a more [adjective] tone, as I will be applying to a [type of company] company. Following is my résumé [resume]. Following is the job description [job description].

Prompt: [Your resume] Enhance my résumé based on this [title] position at [company] and include bullet point achievements that show impact and metrics [Job description]. Note: You can ask ChatGPT to generate the output in LaTex markup.

Interview preparation

With ChatGPT's assistance, you can be well-prepared for your upcoming job interview.

Prompt: I have an interview with [company name] for [job title]. Help me with answers to the following questions:

  1. Information on the company, the industry, and its competitors
  2. The culture of the company
  3. Questions I can ask at the end of the interview

Prompt: I am interviewing for a [job title] role. Please list down the 10 most asked interview questions for a [job title] position.

Example: I am interviewing for a Senior React Developer role. Please list down the 10 most asked interview questions for a Senior React Developer position.

Prompt: I am interviewing for a [job title] role. Please generate 10 interview questions that are specific to the job role posted below [job role]

Prompt: Ask me a random easy/medium/hard Leetcode question and evaluate my solution based on correctness, and the time and space complexity.

Learning

In web development, learning never stops. Whether it's learning new programming languages, understanding best practices, or improving website performance, ChatGPT has you covered.

Prompt: I'm a web developer learning [language/ technology]. Suggest top 5 [social media] [accounts/ channels/ profiles] to follow.

Prompt: What are the best practices when creating a login form?

Prompt: Explain the importance of web accessibility and list three ways to ensure a website is accessible

Prompt: What are some best practices for writing clean and maintainable code in [language/framework]?

Prompt: What are the steps to create a [technology/ framework] blog app with the following requirements?

  1. A listing page of all articles
  2. A detail page where you can read the article
  3. An about me page
  4. Links to social media profiles
  5. Performant

Prompt: What are the differences between [list of similar concepts] in [language/ framework]

Example: What are the differences between var, let, and const keywords in JavaScript

Prompt: Explain [language/ framework] [concept] with a real-world analogy

Example: Explain JavaScript promises with a real-world analogy

Prompt: What are the different ways to improve the performance of a website?

Conclusion

If you're a web developer, using ChatGPT can help optimize your workflow and increase efficiency by providing prompts and strategies to streamline coding tasks. While ChatGPT is a powerful tool, it's important to keep in mind its limitations and use it as a supplement to your knowledge and skills. By fact-checking research and staying up-to-date on current trends, you can fully leverage the benefits of AI in web development. With ChatGPT as a valuable resource, you can confidently navigate the world of web development and enhance your skills.

Introducing Visual Copilot: convert Figma designs to high quality code in a single click.

Try Visual CopilotGet a demo

Share

Twitter
LinkedIn
Facebook
Hand written text that says "A drag and drop headless CMS?"

Introducing Visual Copilot:

A new AI model to turn Figma designs to high quality code using your components.

Try Visual CopilotGet a demo
Newsletter

Like our content?

Join Our Newsletter

Continue Reading
ai8 MIN
The Big Lie AI Vendors Keep Telling You
November 27, 2024
AI8 MIN
Generate Figma Designs with AI
November 25, 2024
Design to code5 MIN
Builder.io Named a Cool Vendor in the 2024 Gartner® Cool Vendors™ in Software Engineering: User Experience
November 21, 2024