[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"blog-categories":6,"course-tree":35,"topic:html-canvas-2d-drawing-api":360},{"data":4},{"google_site_verification":5,"ga4_measurement_id":5,"site_name":5,"default_og_image":5,"twitter_handle":5},null,{"data":7},[8,14,19,25,30],{"name":9,"slug":10,"description":11,"post_count":12,"subcategories":13},"CSS","css","Learn CSS with practical tutorials and examples covering layouts, Flexbox, Grid, responsive design, typography, positioning, animations, and more.",2,[],{"name":15,"slug":16,"description":17,"post_count":12,"subcategories":18},"HTML","html","Learn HTML with practical tutorials and examples for beginners. Explore HTML tags, elements, attributes, links, images, forms, semantic HTML, and more with clear explanations and real code examples.",[],{"name":20,"slug":21,"description":22,"post_count":23,"subcategories":24},"WPF","wpf","Learn WPF with practical tutorials and examples covering XAML, windows, controls, layouts, data binding, MVVM, commands, styles, templates, debugging, and modern WPF UI development.",1,[],{"name":26,"slug":27,"description":28,"post_count":23,"subcategories":29},"Python","python","Learn Python with practical tutorials covering strings, lists, functions, exceptions, files, packages, virtual environments, modules, classes, and beginner programming concepts.",[],{"name":31,"slug":32,"description":33,"post_count":23,"subcategories":34},"Java","java","Learn Java with practical tutorials and examples for beginners. Explore Java syntax, variables, data types, classes, objects, methods, inheritance, exceptions, collections, and more with clear explanations and real code examples.",[],{"data":36},[37],{"id":23,"name":15,"slug":38,"icon":5,"icon_url":5,"short_description":39,"meta_title":40,"meta_description":41,"og_image":42,"locale":43,"subcategories":44},"html-tutorial","Welcome to our HTML Tutorial for Beginners, a complete guide designed to help you learn HTML from the ground up.\n\nHTML, which stands for HyperText Markup Language, is the standard language used to structure content on the web. Whether you want to become a web developer, build your own website, or continue learning CSS and JavaScript, understanding HTML is an essential first step.\n\nThis HTML course takes you through the fundamentals step by step, using simple explanations and practical examples. ","HTML Tutorial for Beginners - Learn HTML Step by Step","Learn HTML from scratch with our beginner-friendly HTML tutorial. Understand HTML tags, elements, forms, tables, links, images, semantic HTML and more with practical examples.","https:\u002F\u002Fwpfsharp.com\u002Fstorage\u002Fcourses\u002Fog\u002F01M2GK0XN45C0B937NF9XFAD4S.webp","en",[45,72,108,132,208,242,256,284,308,324],{"id":23,"name":46,"slug":47,"order_index":23,"topics":48},"HTML Fundamentals & Setup","html-fundamentals-setup",[49,53,56,60,64,68],{"id":23,"title":50,"slug":51,"order_index":23,"cornerstone":52,"reading_time_minutes":23},"HTML Introduction & History","html-introduction-and-history",false,{"id":12,"title":54,"slug":55,"order_index":23,"cornerstone":52,"reading_time_minutes":12},"HTML Editors & Environment Setup","html-editors-and-environment-setup",{"id":57,"title":58,"slug":59,"order_index":57,"cornerstone":52,"reading_time_minutes":12},3,"HTML Basic Syntax & Document Structure","html-basic-syntax-document-structure",{"id":61,"title":62,"slug":63,"order_index":61,"cornerstone":52,"reading_time_minutes":12},4,"HTML Elements & Tags Explained","html-elements-tags-explained",{"id":65,"title":66,"slug":67,"order_index":65,"cornerstone":52,"reading_time_minutes":12},5,"HTML Attributes (Global & Standard)","html-attributes-global-standard",{"id":69,"title":70,"slug":71,"order_index":69,"cornerstone":52,"reading_time_minutes":12},6,"Understanding the DOCTYPE & HTML5 Boilerplate","understanding-doctype-html5-boilerplate",{"id":12,"name":73,"slug":74,"order_index":12,"topics":75},"Text & Content Basics","text-content-basics",[76,80,84,88,92,96,100,104],{"id":77,"title":78,"slug":79,"order_index":77,"cornerstone":52,"reading_time_minutes":12},7,"HTML Headings (H1–H6) & SEO Best Practices","html-headings-h1-h6-seo-best-practices",{"id":81,"title":82,"slug":83,"order_index":81,"cornerstone":52,"reading_time_minutes":12},8,"HTML Paragraphs & Line Breaks","html-paragraphs-line-breaks",{"id":85,"title":86,"slug":87,"order_index":85,"cornerstone":52,"reading_time_minutes":23},9,"HTML Text Formatting (Bold, Italic, Mark, etc.)","html-text-formatting-bold-italic-mark",{"id":89,"title":90,"slug":91,"order_index":89,"cornerstone":52,"reading_time_minutes":12},10,"HTML Styles (Inline CSS Basics)","html-styles-inline-css-basics",{"id":93,"title":94,"slug":95,"order_index":93,"cornerstone":52,"reading_time_minutes":12},11,"HTML Quotations & Citations (blockquote, q, cite)","html-quotations-citations-blockquote-q-cite",{"id":97,"title":98,"slug":99,"order_index":97,"cornerstone":52,"reading_time_minutes":12},12,"HTML Comments (Best Practices)","html-comments-best-practices",{"id":101,"title":102,"slug":103,"order_index":101,"cornerstone":52,"reading_time_minutes":12},13,"HTML Colors (Names, HEX, RGB, HSL)","html-colors-names-hex-rgb-hsl",{"id":105,"title":106,"slug":107,"order_index":105,"cornerstone":52,"reading_time_minutes":12},14,"HTML & CSS Integration (Inline, Internal, External)","html-css-integration-inline-internal-external",{"id":57,"name":109,"slug":110,"order_index":57,"topics":111},"Links, Media & Navigation","links-media-navigation",[112,116,120,124,128],{"id":113,"title":114,"slug":115,"order_index":113,"cornerstone":52,"reading_time_minutes":12},15,"HTML Links (Anchor Tags & Hyperlinks)","html-links-anchor-tags-hyperlinks",{"id":117,"title":118,"slug":119,"order_index":117,"cornerstone":52,"reading_time_minutes":12},16,"HTML Images (Alt Text, Lazy Loading, Formats)","html-images-alt-text-lazy-loading-formats",{"id":121,"title":122,"slug":123,"order_index":121,"cornerstone":52,"reading_time_minutes":23},17,"HTML Favicon Setup","html-favicon-setup",{"id":125,"title":126,"slug":127,"order_index":125,"cornerstone":52,"reading_time_minutes":12},18,"HTML Page Title & Meta Tags (SEO Essentials)","html-page-title-meta-tags-seo-essentials",{"id":129,"title":130,"slug":131,"order_index":129,"cornerstone":52,"reading_time_minutes":12},19,"HTML File Paths (Absolute vs Relative)","html-file-paths-absolute-vs-relative",{"id":61,"name":133,"slug":134,"order_index":61,"topics":135},"Structuring Content","structuring-content",[136,141,146,151,156,160,164,168,172,176,180,184,188,192,196,200,204],{"id":137,"title":138,"slug":139,"order_index":140,"cornerstone":52,"reading_time_minutes":12},24,"HTML Tables Explained: Rows, Columns & Merging Cells","html-tables-rows-columns-merging-cells",20,{"id":142,"title":143,"slug":144,"order_index":145,"cornerstone":52,"reading_time_minutes":12},25,"HTML Lists: Ordered, Unordered & Description Lists","html-lists-ordered-unordered-description",21,{"id":147,"title":148,"slug":149,"order_index":150,"cornerstone":52,"reading_time_minutes":12},26,"HTML Block vs Inline Elements Explained","html-block-vs-inline-elements",22,{"id":152,"title":153,"slug":154,"order_index":155,"cornerstone":52,"reading_time_minutes":23},27,"HTML Div & Span: Generic Containers Explained","html-div-and-span-containers",23,{"id":157,"title":158,"slug":159,"order_index":137,"cornerstone":52,"reading_time_minutes":12},28,"HTML Classes vs ID: Selectors Explained","html-classes-vs-id-selectors-explained",{"id":161,"title":162,"slug":163,"order_index":142,"cornerstone":52,"reading_time_minutes":23},29,"HTML Iframes: Embedding External Content","html-iframes-embedding-content",{"id":165,"title":166,"slug":167,"order_index":147,"cornerstone":52,"reading_time_minutes":12},30,"HTML Head Element Deep Dive","html-head-element-deep-dive",{"id":169,"title":170,"slug":171,"order_index":152,"cornerstone":52,"reading_time_minutes":12},31,"HTML Layout Techniques: Header, Nav & Footer","html-layout-techniques-header-nav-footer",{"id":173,"title":174,"slug":175,"order_index":157,"cornerstone":52,"reading_time_minutes":12},32,"Responsive HTML Design: Mobile-First Approach","responsive-html-design-mobile-first-approach",{"id":177,"title":178,"slug":179,"order_index":161,"cornerstone":52,"reading_time_minutes":57},74,"HTML Semantic Elements (article, section, aside, nav)","html-semantic-elements-article-section-aside-nav",{"id":181,"title":182,"slug":183,"order_index":165,"cornerstone":52,"reading_time_minutes":12},75,"HTML Style Guide & Coding Conventions","html-style-guide-coding-conventions",{"id":185,"title":186,"slug":187,"order_index":169,"cornerstone":52,"reading_time_minutes":12},76,"HTML Entities & Special Characters","html-entities-special-characters",{"id":189,"title":190,"slug":191,"order_index":173,"cornerstone":52,"reading_time_minutes":23},77,"HTML Symbols","html-symbols",{"id":193,"title":194,"slug":195,"order_index":193,"cornerstone":52,"reading_time_minutes":23},33,"HTML Emojis 😀: How to Use Them in Web Pages","html-emojis-trending-guide",{"id":197,"title":198,"slug":199,"order_index":197,"cornerstone":52,"reading_time_minutes":12},34,"HTML Character Sets: UTF-8 & Encoding Explained","html-character-sets-utf-8-encoding",{"id":201,"title":202,"slug":203,"order_index":201,"cornerstone":52,"reading_time_minutes":23},35,"HTML URL Encoding Explained","html-url-encoding-explained",{"id":205,"title":206,"slug":207,"order_index":205,"cornerstone":52,"reading_time_minutes":23},36,"HTML vs XHTML: Key Differences","html-vs-xhtml-key-differences",{"id":77,"name":209,"slug":210,"order_index":65,"topics":211},"Forms & User Input","forms-user-input",[212,217,222,227,232,237],{"id":213,"title":214,"slug":215,"order_index":216,"cornerstone":52,"reading_time_minutes":12},49,"HTML Forms Introduction","html-forms-introduction",37,{"id":218,"title":219,"slug":220,"order_index":221,"cornerstone":52,"reading_time_minutes":23},50,"HTML Form Attributes (action, method, etc.)","html-form-attributes-action-method",38,{"id":223,"title":224,"slug":225,"order_index":226,"cornerstone":52,"reading_time_minutes":23},51,"HTML Form Elements (input, select, textarea, button)","html-form-elements-input-select-textarea-button",39,{"id":228,"title":229,"slug":230,"order_index":231,"cornerstone":52,"reading_time_minutes":12},52,"HTML Input Types (Modern Types: email, date, color, range)","html-input-types-modern-email-date-color-range",40,{"id":233,"title":234,"slug":235,"order_index":236,"cornerstone":52,"reading_time_minutes":12},53,"HTML Input Attributes (required, placeholder, pattern)","html-input-attributes-required-placeholder-pattern",41,{"id":238,"title":239,"slug":240,"order_index":241,"cornerstone":52,"reading_time_minutes":12},54,"HTML Form Validation (Client-Side)","html-form-validation-client-side",42,{"id":81,"name":243,"slug":244,"order_index":69,"topics":245},"Graphics & Visuals","graphics-visuals",[246,251],{"id":247,"title":248,"slug":249,"order_index":250,"cornerstone":52,"reading_time_minutes":57},55,"HTML Canvas (2D Drawing API) 🔥","html-canvas-2d-drawing-api",43,{"id":252,"title":253,"slug":254,"order_index":255,"cornerstone":52,"reading_time_minutes":57},56,"HTML SVG (Scalable Vector Graphics)","html-svg-scalable-vector-graphics",44,{"id":85,"name":257,"slug":258,"order_index":77,"topics":259},"Multimedia","multimedia",[260,265,270,275,280],{"id":261,"title":262,"slug":263,"order_index":264,"cornerstone":52,"reading_time_minutes":12},57,"HTML Media Overview","html-media-overview",45,{"id":266,"title":267,"slug":268,"order_index":269,"cornerstone":52,"reading_time_minutes":12},58,"HTML Video Embedding (Native Player)","html-video-embedding-native-player",46,{"id":271,"title":272,"slug":273,"order_index":274,"cornerstone":52,"reading_time_minutes":12},59,"HTML Audio Embedding","html-audio-embedding",47,{"id":276,"title":277,"slug":278,"order_index":279,"cornerstone":52,"reading_time_minutes":12},60,"HTML Plug-ins (Object & Embed Tags)","html-plugins-object-embed-tags",48,{"id":281,"title":282,"slug":283,"order_index":213,"cornerstone":52,"reading_time_minutes":12},61,"Embedding YouTube Videos in HTML","embedding-youtube-videos-in-html",{"id":89,"name":285,"slug":286,"order_index":81,"topics":287},"HTML5 Web APIs (Advanced\u002FTrending)","html5-web-apis-advancedtrending",[288,292,296,300,304],{"id":289,"title":290,"slug":291,"order_index":218,"cornerstone":52,"reading_time_minutes":12},62,"HTML Geolocation API","html-geolocation-api",{"id":293,"title":294,"slug":295,"order_index":223,"cornerstone":52,"reading_time_minutes":12},63,"HTML Drag & Drop API","html-drag-and-drop-api",{"id":297,"title":298,"slug":299,"order_index":228,"cornerstone":52,"reading_time_minutes":12},64,"HTML Web Storage (localStorage & sessionStorage)","html-web-storage-localstorage-sessionstorage",{"id":301,"title":302,"slug":303,"order_index":233,"cornerstone":52,"reading_time_minutes":12},65,"HTML Web Workers (Background Processing)","html-web-workers-background-processing",{"id":305,"title":306,"slug":307,"order_index":238,"cornerstone":52,"reading_time_minutes":12},66,"HTML Server-Sent Events (SSE)","html-server-sent-events-sse",{"id":93,"name":309,"slug":310,"order_index":85,"topics":311},"Accessibility & Best Practices (High-Demand  Skill) �","accessibility-best-practices-high-demand-skill",[312,316,320],{"id":313,"title":314,"slug":315,"order_index":247,"cornerstone":52,"reading_time_minutes":12},67,"HTML Accessibility (ARIA, Screen Readers)","html-accessibility-aria-screen-readers",{"id":317,"title":318,"slug":319,"order_index":252,"cornerstone":52,"reading_time_minutes":12},68,"Writing Semantic & SEO-Friendly HTML","writing-semantic-and-seo-friendly-html",{"id":321,"title":322,"slug":323,"order_index":261,"cornerstone":52,"reading_time_minutes":12},69,"HTML Performance Optimization Basics","html-performance-optimization-basics",{"id":97,"name":325,"slug":326,"order_index":89,"topics":327},"Reference & Practice","reference-practice",[328,332,336,340,344,348,352,356],{"id":329,"title":330,"slug":331,"order_index":23,"cornerstone":52,"reading_time_minutes":12},70,"HTML Tag List (Full Reference)","html-tag-list-full-reference",{"id":333,"title":334,"slug":335,"order_index":12,"cornerstone":52,"reading_time_minutes":12},71,"HTML Global Attributes Reference","html-global-attributes-reference",{"id":337,"title":338,"slug":339,"order_index":57,"cornerstone":52,"reading_time_minutes":12},72,"HTML Events Reference","html-events-reference",{"id":341,"title":342,"slug":343,"order_index":61,"cornerstone":52,"reading_time_minutes":12},73,"HTML Browser Support & Compatibility","html-browser-support-compatibility",{"id":345,"title":346,"slug":347,"order_index":65,"cornerstone":52,"reading_time_minutes":12},78,"HTML Doctypes Reference","html-doctypes-reference",{"id":349,"title":350,"slug":351,"order_index":69,"cornerstone":52,"reading_time_minutes":12},79,"HTTP Methods & Messages (Basics for Forms\u002FAPIs)","http-methods-messages-basics",{"id":353,"title":354,"slug":355,"order_index":77,"cornerstone":52,"reading_time_minutes":57},80,"HTML Interview Preparation (Top Q&A)","html-interview-preparation-top-qa",{"id":357,"title":358,"slug":359,"order_index":81,"cornerstone":52,"reading_time_minutes":23},81,"HTML Quiz & Practice Exercises","html-quiz-practice-exercises",{"data":361},{"id":247,"title":248,"slug":249,"content":362,"course":363,"subcategory":364,"author":365,"reading_time_minutes":57,"cornerstone":52,"schema_type":371,"faq_json":5,"video_url":5,"canonical_url":372,"meta_title":373,"meta_description":374,"og_image":5,"toc_json":375,"code_examples":416,"quiz":5,"exercises":428,"published_at":5,"updated_at":435,"prev":436,"next":437},"\u003Ch1 id=\"html-canvas-2d-drawing-api\">HTML Canvas (2D Drawing API)\u003C\u002Fh1>\u003Cp>The \u003Ccode>&lt;canvas&gt;\u003C\u002Fcode> element gives you a blank, pixel-based drawing surface directly in the browser. Using JavaScript, you can draw shapes, lines, text, images, and even build full animations and games &mdash; all without any external library. This is one of the most powerful and trending topics &#128293; in modern web development, powering everything from data visualizations and charting libraries to browser-based games and generative art.\u003C\u002Fp>\u003Ch2 id=\"what-is-the-canvas-element\">What Is the Canvas Element?\u003C\u002Fh2>\u003Cp>\u003Ccode>&lt;canvas&gt;\u003C\u002Fcode> is just a container in your HTML. On its own it draws nothing &mdash; it needs a JavaScript \u003Cstrong>rendering context\u003C\u002Fstrong> to actually draw pixels onto it.\u003C\u002Fp>\u003Cpre>\u003Ccode>&lt;canvas id=\"myCanvas\" width=\"400\" height=\"200\"&gt;&lt;\u002Fcanvas&gt;\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"getting-the-2d-context\">Getting the 2D Context\u003C\u002Fh2>\u003Cp>You access the drawing API through \u003Ccode>getContext('2d')\u003C\u002Fcode>, which returns an object with all the drawing methods you'll use.\u003C\u002Fp>\u003Cpre>\u003Ccode>const canvas = document.getElementById('myCanvas');\nconst ctx = canvas.getContext('2d');\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"drawing-shapes\">Drawing Shapes\u003C\u002Fh2>\u003Cp>The Canvas API gives you built-in methods for rectangles, and a flexible path system for any custom shape.\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F Filled rectangle\nctx.fillStyle = 'dodgerblue';\nctx.fillRect(20, 20, 150, 100);\n\n\u002F\u002F Stroked (outlined) rectangle\nctx.strokeStyle = 'darkred';\nctx.lineWidth = 4;\nctx.strokeRect(200, 20, 150, 100);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"drawing-paths-lines-circles-custom-shapes\">Drawing Paths (Lines, Circles, Custom Shapes)\u003C\u002Fh2>\u003Cp>For anything more complex than a rectangle, you build a \u003Cstrong>path\u003C\u002Fstrong> using \u003Ccode>beginPath()\u003C\u002Fcode>, move and draw commands, and then \u003Ccode>fill()\u003C\u002Fcode> or \u003Ccode>stroke()\u003C\u002Fcode> it.\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F Circle\nctx.beginPath();\nctx.arc(100, 200, 50, 0, Math.PI * 2);\nctx.fillStyle = 'orange';\nctx.fill();\n\n\u002F\u002F Line\nctx.beginPath();\nctx.moveTo(50, 300);\nctx.lineTo(350, 300);\nctx.strokeStyle = 'black';\nctx.stroke();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"adding-text\">Adding Text\u003C\u002Fh2>\u003Cp>Canvas can render styled text directly onto the pixel surface &mdash; useful for watermarks, dynamic banners, and chart labels.\u003C\u002Fp>\u003Cpre>\u003Ccode>ctx.font = '24px Arial';\nctx.fillStyle = 'black';\nctx.fillText('Hello Canvas!', 50, 150);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"drawing-images\">Drawing Images\u003C\u002Fh2>\u003Cp>You can also draw existing images onto the canvas, which is the foundation of photo editors and meme generators built in the browser.\u003C\u002Fp>\u003Cpre>\u003Ccode>const img = new Image();\nimg.src = 'photo.jpg';\nimg.onload = function() {\n  ctx.drawImage(img, 0, 0, 200, 150);\n};\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"animation-with-requestanimationframe\">Animation with requestAnimationFrame\u003C\u002Fh2>\u003Cp>Real-time animation (a trending use-case for browser games and interactive dashboards) is done by clearing and redrawing the canvas repeatedly using \u003Ccode>requestAnimationFrame\u003C\u002Fcode>, which syncs drawing with the screen's refresh rate for smooth motion.\u003C\u002Fp>\u003Cpre>\u003Ccode>let x = 0;\nfunction animate() {\n  ctx.clearRect(0, 0, canvas.width, canvas.height);\n  ctx.beginPath();\n  ctx.arc(x, 100, 20, 0, Math.PI * 2);\n  ctx.fillStyle = 'purple';\n  ctx.fill();\n  x = (x + 2) % canvas.width;\n  requestAnimationFrame(animate);\n}\nanimate();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2 id=\"canvas-vs-svg-when-to-use-canvas\">Canvas vs SVG: When to Use Canvas\u003C\u002Fh2>\u003Cp>Canvas is pixel-based (immediate mode) &mdash; great for performance-heavy scenes with lots of moving objects, like games, particle effects, or real-time data visualizations, because the browser doesn't need to track thousands of individual DOM elements.\u003C\u002Fp>\u003Ch2 id=\"common-beginner-mistakes\">Common Beginner Mistakes\u003C\u002Fh2>\u003Cul>\u003Cli>Forgetting to call \u003Ccode>clearRect()\u003C\u002Fcode> before redrawing each animation frame, causing motion trails\u003C\u002Fli>\u003Cli>Setting \u003Ccode>width\u003C\u002Fcode>\u002F\u003Ccode>height\u003C\u002Fcode> via CSS instead of HTML attributes, which stretches and blurs the drawing\u003C\u002Fli>\u003Cli>Not waiting for images to load (\u003Ccode>onload\u003C\u002Fcode>) before calling \u003Ccode>drawImage()\u003C\u002Fcode>\u003C\u002Fli>\u003C\u002Ful>\u003Ch2 id=\"live-example\">Live Example\u003C\u002Fh2>\u003Cp>Edit the code below to change colors, shapes, or the animation speed and see the canvas update instantly.\u003C\u002Fp>\u003Cdiv class=\"try-it-yourself language-html\">\u003Cpre>\u003Ccode>&lt;canvas id='demoCanvas' width='400' height='250' style='border:1px solid #ccc; background:#fafafa;'&gt;&lt;\u002Fcanvas&gt;\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003Cdiv class=\"try-it-yourself language-javascript\">\u003Cpre>\u003Ccode>const canvas = document.getElementById('demoCanvas');\nconst ctx = canvas.getContext('2d');\n\n\u002F\u002F Rectangle\nctx.fillStyle = 'dodgerblue';\nctx.fillRect(20, 20, 120, 80);\n\n\u002F\u002F Circle\nctx.beginPath();\nctx.arc(280, 60, 40, 0, Math.PI * 2);\nctx.fillStyle = 'orange';\nctx.fill();\n\n\u002F\u002F Line\nctx.beginPath();\nctx.moveTo(20, 150);\nctx.lineTo(380, 150);\nctx.strokeStyle = 'black';\nctx.lineWidth = 3;\nctx.stroke();\n\n\u002F\u002F Text\nctx.font = '20px Arial';\nctx.fillStyle = 'black';\nctx.fillText('Canvas 2D Drawing!', 60, 210);\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003Cdiv class=\"try-it-yourself language-javascript\">\u003Cpre>\u003Ccode>const canvas2 = document.getElementById('demoCanvas');\nconst ctx2 = canvas2.getContext('2d');\nlet x = 0;\n\nfunction animate() {\n  ctx2.clearRect(0, 0, canvas2.width, canvas2.height);\n  ctx2.beginPath();\n  ctx2.arc(x, 125, 20, 0, Math.PI * 2);\n  ctx2.fillStyle = 'purple';\n  ctx2.fill();\n  x = (x + 3) % canvas2.width;\n  requestAnimationFrame(animate);\n}\nanimate();\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>",{"name":15,"slug":38},{"name":243,"slug":244},{"slug":366,"display_name":367,"job_title":5,"short_bio":5,"expertise_tags":368,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":369,"posts":370},"badar-khalil","Badar Khalil",[],[],[],"Article","https:\u002F\u002Fwpfsharp.com\u002Ftopics\u002Fhtml-canvas-2d-drawing-api","HTML Canvas Tutorial: 2D Drawing API Guide 2026","Learn HTML5 canvas tutorial with live 2D drawing API examples: shapes, paths, colors, text, images, animation and game basics.",[376,380,384,388,392,396,400,404,408,412],{"id":377,"text":378,"level":12,"children":379},"what-is-the-canvas-element","What Is the Canvas Element?",[],{"id":381,"text":382,"level":12,"children":383},"getting-the-2d-context","Getting the 2D Context",[],{"id":385,"text":386,"level":12,"children":387},"drawing-shapes","Drawing Shapes",[],{"id":389,"text":390,"level":12,"children":391},"drawing-paths-lines-circles-custom-shapes","Drawing Paths (Lines, Circles, Custom Shapes)",[],{"id":393,"text":394,"level":12,"children":395},"adding-text","Adding Text",[],{"id":397,"text":398,"level":12,"children":399},"drawing-images","Drawing Images",[],{"id":401,"text":402,"level":12,"children":403},"animation-with-requestanimationframe","Animation with requestAnimationFrame",[],{"id":405,"text":406,"level":12,"children":407},"canvas-vs-svg-when-to-use-canvas","Canvas vs SVG: When to Use Canvas",[],{"id":409,"text":410,"level":12,"children":411},"common-beginner-mistakes","Common Beginner Mistakes",[],{"id":413,"text":414,"level":12,"children":415},"live-example","Live Example",[],[417,421,425],{"id":418,"language":16,"code":419,"is_editable":420},118,"\u003Ccanvas id='demoCanvas' width='400' height='250' style='border:1px solid #ccc; background:#fafafa;'>\u003C\u002Fcanvas>",true,{"id":422,"language":423,"code":424,"is_editable":420},119,"javascript","const canvas = document.getElementById('demoCanvas');\nconst ctx = canvas.getContext('2d');\n\n\u002F\u002F Rectangle\nctx.fillStyle = 'dodgerblue';\nctx.fillRect(20, 20, 120, 80);\n\n\u002F\u002F Circle\nctx.beginPath();\nctx.arc(280, 60, 40, 0, Math.PI * 2);\nctx.fillStyle = 'orange';\nctx.fill();\n\n\u002F\u002F Line\nctx.beginPath();\nctx.moveTo(20, 150);\nctx.lineTo(380, 150);\nctx.strokeStyle = 'black';\nctx.lineWidth = 3;\nctx.stroke();\n\n\u002F\u002F Text\nctx.font = '20px Arial';\nctx.fillStyle = 'black';\nctx.fillText('Canvas 2D Drawing!', 60, 210);",{"id":426,"language":423,"code":427,"is_editable":420},120,"const canvas2 = document.getElementById('demoCanvas');\nconst ctx2 = canvas2.getContext('2d');\nlet x = 0;\n\nfunction animate() {\n  ctx2.clearRect(0, 0, canvas2.width, canvas2.height);\n  ctx2.beginPath();\n  ctx2.arc(x, 125, 20, 0, Math.PI * 2);\n  ctx2.fillStyle = 'purple';\n  ctx2.fill();\n  x = (x + 3) % canvas2.width;\n  requestAnimationFrame(animate);\n}\nanimate();",[429],{"id":233,"title":430,"slug":431,"prompt":432,"starter_code":433,"expected_output":434,"language":423,"order_index":23},"Draw a Simple Smiley Face","draw-a-simple-smiley-face","Using the 2D canvas context, draw a smiley face: one large yellow circle for the face, two small black circles for eyes, and an arc for the mouth.","const canvas = document.getElementById('demoCanvas');\nconst ctx = canvas.getContext('2d');\n\n\u002F\u002F TODO: draw yellow face circle\n\n\u002F\u002F TODO: draw two small black eye circles\n\n\u002F\u002F TODO: draw a curved arc for the mouth","A canvas drawing showing a yellow circular face, two black eye circles, and a curved mouth arc.","2026-09-27T18:25:08+00:00",{"id":238,"slug":240,"title":239},{"id":252,"slug":254,"title":253}]