<?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: Lavkush Kumar</title>
    <description>The latest articles on DEV Community by Lavkush Kumar (@kushkrg).</description>
    <link>https://dev.to/kushkrg</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1230268%2F61326777-e179-4941-a7f2-2be6372553e3.PNG</url>
      <title>DEV Community: Lavkush Kumar</title>
      <link>https://dev.to/kushkrg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kushkrg"/>
    <language>en</language>
    <item>
      <title>How to Make a Main Menu in Godot 4</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Sat, 05 Dec 2026 05:40:22 +0000</pubDate>
      <link>https://dev.to/kushkrg/how-to-make-a-main-menu-in-godot-4-jol</link>
      <guid>https://dev.to/kushkrg/how-to-make-a-main-menu-in-godot-4-jol</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/how-to-make-a-main-menu-in-godot-4" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A main menu is the first screen your player sees, and in Godot 4 it is a scene like any other: a Control that fills the window, a stack of buttons in the middle, and a short script that loads the game when Start is pressed. This post builds one for a small game called Space Rescue: a title, Start, How to Play and Quit buttons, plus a small panel that opens and closes. Every line of code here was run in Godot 4.3. If you prefer watching, the video version is in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The menu we are building
&lt;/h2&gt;

&lt;p&gt;The project has two scenes: menu.tscn is the menu, and game.tscn is the game it loads. Our game scene is a placeholder with one label that says "You are in the game now." In a real project, point Start at your own level, for example the player from &lt;a href="https://codingcush.com/how-to-move-a-character-in-godot-4-gdscript" rel="noopener noreferrer"&gt;how to move a character in Godot 4 with GDScript&lt;/a&gt;. The menu itself is built from six nodes: a Control root, a CenterContainer, a VBoxContainer, a Label for the title, three Buttons, and a PanelContainer that stays hidden until the player asks for help. Buttons in Godot respond to mouse, keyboard and touch without extra code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scene tree, piece by piece
&lt;/h2&gt;

&lt;p&gt;Start with a new scene whose root is a Control, the base node for every user interface element in Godot. Select it, open the Layout menu at the top of the 2D view, and pick Anchors Preset, then Full Rect, so the menu fills the screen at any window size. Skip this step and the menu fills only part of the window.&lt;/p&gt;

&lt;p&gt;Add a CenterContainer as a child of the root, with the same Full Rect anchors. It puts its children in the middle of the space it gets, so the title and buttons stay centred on any screen size, with no numbers to recalculate.&lt;/p&gt;

&lt;p&gt;Inside the CenterContainer, add a VBoxContainer. It stacks its children top to bottom and decides their positions for you. Set its Separation to 16 so the rows breathe. Add a Label first: text SPACE RESCUE, font size 64, alignment centre. Then add three Buttons, Start Game, How to Play and Quit, each 260 by 56 with a font size of 24, big enough to tap on a phone screen.&lt;/p&gt;

&lt;p&gt;The last node is the How to Play panel. Add a PanelContainer as a child of the root, not of the VBoxContainer, because it should float over the menu instead of joining the stack. Set its Visible property off, so the player never sees it until the button is pressed. Inside it, put a VBoxContainer with a Label that explains the controls and a Button that says Got it. The panel draws its own background box for the text to sit on.&lt;/p&gt;

&lt;p&gt;One rule runs through all of this. Once a Control sits inside a container, the container places it: children give up their own positioning, and dragging them by hand is ignored or undone the next time the parent resizes. So do not drag the buttons into place. Set the separation and the sizes, and let the containers do the arranging. &lt;a href="https://docs.godotengine.org/en/stable/tutorials/ui/gui_containers.html" rel="noopener noreferrer"&gt;Godot's guide to using containers&lt;/a&gt; lists every container type, and most menus need only the two used here.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvdozg1oernjrx04cutwa.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvdozg1oernjrx04cutwa.png" alt="The Godot 4 editor showing the Space Rescue main menu scene: the scene tree on the left and the title with three buttons in the 2D view" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Godot 4 editor showing the Space Rescue main menu scene: the scene tree on the left and the title with three buttons in the 2D view.&lt;/p&gt;

&lt;h2&gt;
  
  
  The script that makes the buttons work
&lt;/h2&gt;

&lt;p&gt;Buttons that do nothing are just rectangles. Attach this script to the menu root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Control

@onready var start_button: Button = $Center/MenuBox/StartButton
@onready var howto_button: Button = $Center/MenuBox/HowToButton
@onready var quit_button: Button = $Center/MenuBox/QuitButton
@onready var howto_panel: PanelContainer = $HowToPanel
@onready var close_button: Button = $HowToPanel/PanelBox/CloseButton

func _ready() -&amp;gt; void:
    start_button.pressed.connect(_on_start_button_pressed)
    howto_button.pressed.connect(_on_howto_button_pressed)
    quit_button.pressed.connect(_on_quit_button_pressed)
    close_button.pressed.connect(_on_close_button_pressed)

func _on_start_button_pressed() -&amp;gt; void:
    get_tree().change_scene_to_file("res://game.tscn")

func _on_howto_button_pressed() -&amp;gt; void:
    howto_panel.visible = true

func _on_close_button_pressed() -&amp;gt; void:
    howto_panel.visible = false

func _on_quit_button_pressed() -&amp;gt; void:
    get_tree().quit()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The @onready lines grab the nodes when the scene loads, using the same paths you see in the Scene dock. The dollar sign is shorthand for get_node. Rename a node in the dock and the path in the script must change to match, or the game reports the node was not found.&lt;/p&gt;

&lt;p&gt;The four connect lines in _ready are where the buttons come alive. pressed is a signal a Button emits when the player clicks or taps it, and connect tells Godot which function to run when it fires. &lt;a href="https://codingcush.com/godot-4-signals-explained" rel="noopener noreferrer"&gt;How Godot signals work&lt;/a&gt; explains the same pattern in full, but for a menu this code version is the shortest path.&lt;/p&gt;

&lt;p&gt;The Start handler calls get_tree().change_scene_to_file with the path of the game scene. The path must match the file exactly, starting with res://, spelling and .tscn ending included. The call returns an error code, 0 when it worked, and the switch happens at the end of the current frame. &lt;a href="https://docs.godotengine.org/en/stable/classes/class_scenetree.html" rel="noopener noreferrer"&gt;The SceneTree reference&lt;/a&gt; lists the other ways to change scenes. I ran this exact script in Godot 4.3 and pressed Start in a headless test: the game scene loaded with its label showing.&lt;/p&gt;

&lt;p&gt;The How to Play handler sets the panel visible to true, and Got it sets it back to false. The Quit handler calls get_tree().quit(), which closes the running game. It does nothing inside the editor, because the editor is not the running game, so test it by running the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anchors or containers
&lt;/h2&gt;

&lt;p&gt;New Godot users mix these two up, because both move controls around. They solve different problems:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Reach for it when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Anchors&lt;/td&gt;
&lt;td&gt;Pin a control to its parent's edges, so it stretches or stays put as the window resizes&lt;/td&gt;
&lt;td&gt;A panel must fill the screen, or a button must stay in one corner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Containers&lt;/td&gt;
&lt;td&gt;Arrange children in a row, column or grid, and redo the layout on every resize&lt;/td&gt;
&lt;td&gt;Several buttons or labels must sit in a neat stack&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A menu uses both: anchors so it always fills the window, containers so the buttons stack neatly in the middle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where menus usually break
&lt;/h2&gt;

&lt;p&gt;Most menu bugs have the same shape: the screen looks right, and nothing happens when you click.&lt;/p&gt;

&lt;p&gt;First, the button does nothing. The pressed signal was never connected, which usually means the connect line is missing from _ready, or the script sits on the wrong node. Check the Node dock: select a button, open the Node tab, and look for pressed.&lt;/p&gt;

&lt;p&gt;Second, the menu fills only part of the window. The root Control never got its Full Rect anchors. Select the root, open the Layout menu, pick Full Rect, then do the same for the CenterContainer.&lt;/p&gt;

&lt;p&gt;Third, Start shows an error instead of the game. The path in change_scene_to_file is wrong, and the error names the path it could not find. Copy the path from the FileSystem dock instead of typing it.&lt;/p&gt;

&lt;p&gt;Fourth, Quit seems broken. It only closes a running game, so pressing it while the editor is open does nothing visible. Run the project, press Quit, and the game window closes. On a web export the same button often does nothing, because a web page cannot close its own tab, so hide the Quit button on web builds or swap it for a link back to your site.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions beginners actually ask
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can I build the whole menu in code instead of the editor?
&lt;/h3&gt;

&lt;p&gt;Yes. Button.new() creates a button: set its text, connect its pressed signal and add it as a child, and the docs show the same pattern. The editor is faster for a first menu, because you see the layout as you build it. Code is the right choice when buttons are generated at run time, like a list of saved games.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do my buttons look plain and grey?
&lt;/h3&gt;

&lt;p&gt;They use Godot's default theme, which is plain on purpose. A theme is a separate job: it sets colours, fonts and borders for every control at once. Learn the layout first, then dress it up.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I go back to the menu from the game?
&lt;/h3&gt;

&lt;p&gt;The same call, in the other direction: from the game, call get_tree().change_scene_to_file("res://menu.tscn") on a pause menu button or a key press. The menu scene loads fresh each time, so the How to Play panel starts hidden again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the menu need its own script file?
&lt;/h3&gt;

&lt;p&gt;One script on the menu root covers every button. Splitting the handlers across several scripts only makes the connections harder to find later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;You now have a menu with a title, three working buttons and a panel, built from six nodes and one short script. Try two small changes before you move on: add a Settings button that opens a second panel, and give the title screen a living character with &lt;a href="https://codingcush.com/how-to-animate-a-sprite-in-godot-4" rel="noopener noreferrer"&gt;how to animate a sprite in Godot 4&lt;/a&gt;. When the menu feels like yours, the next lesson is waiting in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>gdscript</category>
      <category>gamedev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Animate a Sprite in Godot 4 with AnimatedSprite2D</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Fri, 04 Dec 2026 05:58:56 +0000</pubDate>
      <link>https://dev.to/kushkrg/how-to-animate-a-sprite-in-godot-4-with-animatedsprite2d-1237</link>
      <guid>https://dev.to/kushkrg/how-to-animate-a-sprite-in-godot-4-with-animatedsprite2d-1237</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/how-to-animate-a-sprite-in-godot-4" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A still sprite looks fine in a screenshot, and dead in a game. The moment your character should walk, the picture has to change, frame by frame, about ten times a second. In Godot 4 the node that does that job is AnimatedSprite2D, and the list of pictures it cycles through lives in a SpriteFrames resource. This post builds a small character with three animations, idle, walk and jump, in six steps, with code tested in Godot 4.3. If you would rather watch the lesson, the video version is in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two pieces you need
&lt;/h2&gt;

&lt;p&gt;Animation in Godot 4 has two halves. AnimatedSprite2D is the node in your scene: it draws one frame at a time and knows which animation is playing. SpriteFrames is a resource that holds the pictures, grouped into named animations, each with its own speed. One node holds one SpriteFrames resource, and that resource can hold as many animations as you like, so one character node can carry idle, walk and jump.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: add an AnimatedSprite2D to your player
&lt;/h2&gt;

&lt;p&gt;Start with the player scene from &lt;a href="https://codingcush.com/how-to-move-a-character-in-godot-4-gdscript" rel="noopener noreferrer"&gt;how to move a character in Godot 4 with GDScript&lt;/a&gt;, a CharacterBody2D with a CollisionShape2D. Select the player, add a child node, and pick AnimatedSprite2D. If the player already has a plain Sprite2D, delete it, because two nodes drawing the same character will overlap.&lt;/p&gt;

&lt;p&gt;The AnimatedSprite2D must sit under the body that moves, so it follows the player instead of staying behind on the floor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: make a SpriteFrames resource and add your frames
&lt;/h2&gt;

&lt;p&gt;Select the AnimatedSprite2D and look at the Inspector. The first property under Animation is Sprite Frames, and it is empty. Click it, pick New SpriteFrames, and a SpriteFrames panel opens at the bottom of the editor.&lt;/p&gt;

&lt;p&gt;On the left is the animations list, starting with one animation called default. In the middle is the frame strip, empty for now. Drag your pictures from the FileSystem dock into the frame strip. For this post I drew eight small frames with a script: two for idle, four for walk, two for jump. If you want real game art instead of drawn shapes, grab our &lt;a href="https://codingcush.com/catch-the-fruit-free-art-pack-for-the-godot-4-hindi-course" rel="noopener noreferrer"&gt;free Catch the Fruit art pack&lt;/a&gt; and drop its fruit pictures in the same way. The steps are identical whatever pictures you use. &lt;a href="https://docs.godotengine.org/en/stable/tutorials/2d/2d_sprite_animation.html" rel="noopener noreferrer"&gt;Godot's 2D sprite animation tutorial&lt;/a&gt; covers the same panel with its own pictures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: name the animations and set the speed
&lt;/h2&gt;

&lt;p&gt;One animation called default tells you nothing. Rename it to idle, then click Add Animation and make walk and jump the same way, dragging the matching frames into each. The name is what your code asks for later, so spell it once and use that spelling everywhere. A typo here is the most common reason an animation refuses to play, and the error names the missing animation.&lt;/p&gt;

&lt;p&gt;Each animation also has a speed, in frames per second. Idle runs at 5 FPS here, slow enough to read as breathing. Walk runs at 10 FPS, fast enough to read as steps. Jump runs at 8 FPS. Speed belongs to the animation, not the node, so idle and walk can run at different rates. Press Play at the top right of the panel to preview, and adjust the number until the motion feels right.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0xpjpl68528nu9eo6do.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0xpjpl68528nu9eo6do.png" alt="The SpriteFrames panel in the Godot 4 editor, with the idle and walk animations for the demo character" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The SpriteFrames panel in the Godot 4 editor, with the idle and walk animations for the demo character.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: play the right animation from code
&lt;/h2&gt;

&lt;p&gt;The editor shows your pictures. Your code decides when each animation runs. Attach this script to the player:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends CharacterBody2D

@export var speed = 300.0
@onready var animated_sprite = $AnimatedSprite2D

func _physics_process(_delta):
    var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    velocity = direction * speed
    update_animation(direction)
    move_and_slide()

func update_animation(direction):
    if direction.x != 0:
        animated_sprite.flip_h = direction.x &amp;lt; 0
    if direction != Vector2.ZERO:
        animated_sprite.play("walk")
    else:
        animated_sprite.play("idle")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those two calls are the whole trick: you never touch individual frames in code, you only name the animation you want.&lt;/p&gt;

&lt;p&gt;One detail worth knowing: calling play("walk") on every physics frame does not restart the cycle. Godot keeps playing from the frame it already reached. I checked this in a headless test on Godot 4.3, where calling play() again left the frame and the progress exactly where they were. &lt;a href="https://docs.godotengine.org/en/stable/getting_started/first_2d_game/03.coding_the_player.html" rel="noopener noreferrer"&gt;The first 2D game tutorial&lt;/a&gt; uses the same pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: flip the sprite instead of drawing it twice
&lt;/h2&gt;

&lt;p&gt;Our walk cycle faces right. For walking left, you do not need a second set of pictures. AnimatedSprite2D has a flip_h property, and the script sets it from the direction: true when the player moves left, false when moving right. One line, and the same four frames serve both directions.&lt;/p&gt;

&lt;p&gt;There is a matching flip_v for vertical flips, but a walk cycle flipped upside down looks wrong, so save it for things like a projectile flying downward.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: play a one-shot animation and catch the end
&lt;/h2&gt;

&lt;p&gt;Idle and walk loop forever, which is what you want for them. A jump should play once and hand control back to idle. That is what the animation_finished signal is for: it fires when a non-looping animation reaches its last frame, and stays quiet while a looping animation runs.&lt;/p&gt;

&lt;p&gt;Set the jump animation to not loop in the SpriteFrames panel, then play it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func play_jump():
    animated_sprite.play("jump")
    await animated_sprite.animation_finished
    animated_sprite.play("idle")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The await line pauses the function until the signal fires, then the next line runs. In the headless test the signal fired with the animation stopped on its last frame, and play("idle") started the breathing loop again. Signals work the same way for button presses and coin pickups, and &lt;a href="https://codingcush.com/godot-4-signals-explained" rel="noopener noreferrer"&gt;how Godot signals work&lt;/a&gt; explains the pattern in full.&lt;/p&gt;

&lt;h2&gt;
  
  
  AnimatedSprite2D, Sprite2D, or AnimationPlayer
&lt;/h2&gt;

&lt;p&gt;Godot has three ways to show a moving picture:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Node&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;th&gt;What it cannot do&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AnimatedSprite2D&lt;/td&gt;
&lt;td&gt;Frame-by-frame character animation&lt;/td&gt;
&lt;td&gt;Move anything except the picture itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sprite2D&lt;/td&gt;
&lt;td&gt;One still picture, or a picture you move by hand&lt;/td&gt;
&lt;td&gt;Play a sequence of frames on its own&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AnimationPlayer&lt;/td&gt;
&lt;td&gt;Moving, fading and scaling several things at once&lt;/td&gt;
&lt;td&gt;Keep frame lists as simple as SpriteFrames&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a character that walks, idles and jumps, AnimatedSprite2D is the right tool, because the whole job is choosing which list of pictures to show. Reach for AnimationPlayer when one animation has to move the node and change its look at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five mistakes that stop animations working
&lt;/h2&gt;

&lt;p&gt;Most animation bugs look the same on screen: the character stands still. Work through this list in order.&lt;/p&gt;

&lt;p&gt;First, the animation name in code does not match the name in the panel. The names are case sensitive, and "Walk" is not "walk". Read the error message before changing anything else: it names the missing animation.&lt;/p&gt;

&lt;p&gt;Second, the SpriteFrames resource was never assigned. Its Sprite Frames property is empty, so there is nothing to play. Select the AnimatedSprite2D and check the Inspector.&lt;/p&gt;

&lt;p&gt;Third, the speed is wrong for the feeling you want. A walk at 2 FPS looks like a slideshow, and an idle at 30 FPS looks like shivering. Start at 8 to 10 FPS for a walk and 4 to 5 for an idle.&lt;/p&gt;

&lt;p&gt;Fourth, the frames are in the wrong order. Drag the frames in the strip until the order reads left foot, together, right foot, together, or the character looks like it is tripping.&lt;/p&gt;

&lt;p&gt;Fifth, animation_finished never fires. It only fires for animations that do not loop. A looping jump never sends the signal, so check the loop checkbox, or the await after it waits forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions beginners actually ask
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How many frames does a walk cycle need?
&lt;/h3&gt;

&lt;p&gt;Four is enough: left foot forward, feet together, right foot forward, feet together. Two can work for a simple top-down character. More than eight is usually wasted effort, because the frames flash past too fast to see.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can one AnimatedSprite2D hold several characters?
&lt;/h3&gt;

&lt;p&gt;It can hold as many animations as you like, but one node draws one character. Give each character its own node and its own SpriteFrames resource.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does my character slide without moving its legs?
&lt;/h3&gt;

&lt;p&gt;The movement code runs but the animation never starts, which usually means play() is never called, or something calls stop() after it. Check that your update function runs every physics frame.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I use AnimatedSprite2D or AnimationPlayer for a player character?
&lt;/h3&gt;

&lt;p&gt;Start with AnimatedSprite2D. It covers idle, walk, jump and attack with the least setup. Move to AnimationPlayer when one animation has to move the node and change its look at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;You now have a character that breathes when it stands still, walks when it moves, and jumps once when you tell it to. Add a fourth animation to the same SpriteFrames resource, an attack or a hurt pose, and wire it to a key press the way Step 6 wired the jump. When you are ready for the next lesson, the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt; picks up from here.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>gdscript</category>
      <category>gamedev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Godot 4 Signals Explained: How Nodes Talk to Each Other</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Thu, 03 Dec 2026 05:32:25 +0000</pubDate>
      <link>https://dev.to/kushkrg/godot-4-signals-explained-how-nodes-talk-to-each-other-5044</link>
      <guid>https://dev.to/kushkrg/godot-4-signals-explained-how-nodes-talk-to-each-other-5044</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/godot-4-signals-explained" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A signal in Godot 4 is a message a node sends when something happens. A button sends one when it gets pressed, and a coin sends one when the player touches it. Any other node can listen for that message and run a function when it arrives, and the sender never needs to know who is listening. Think of a doorbell. The button by the door has no idea who lives in the house, and it does not need to know. It rings, and whoever is inside decides what to do about it. A signal works the same way. This post builds a coin game to show you how, with code run in Godot 4.3 first. If you would rather watch the lesson, the video version is in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a signal is, in plain words
&lt;/h2&gt;

&lt;p&gt;Every node in Godot can send signals, and every node can listen for them. The sender is the emitter, the message is the signal, and the function that runs when it arrives is the receiver. A signal carries no return value and waits for no answer. It announces that something happened, and then it is done.&lt;/p&gt;

&lt;p&gt;Godot ships with built-in signals on most nodes. A Button has pressed. A Timer has timeout. An Area2D has body_entered, which fires when a body walks into it. You can also define your own: a coin can announce collected, a player can announce died, a level can announce finished. Since Godot 4.0, signals are a first-class type, so the editor can autocomplete them instead of making you spell their names as strings.&lt;/p&gt;

&lt;p&gt;Signals exist so your nodes can stay strangers to each other. The coin does not need a reference to the score label, and the score label does not need to know what a coin is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The coin game we will build
&lt;/h2&gt;

&lt;p&gt;The example for this post is small on purpose: a coin, a score label, and a button. The player walks into the coin, the coin announces it, and the score goes up by one. Every bigger use of signals is the same shape with more nodes.&lt;/p&gt;

&lt;p&gt;The scene tree looks like this. Main is a Node2D. Under it sit Coin (an Area2D with a CollisionShape2D and a Sprite2D), a Label called ScoreLabel, and a Button called CollectButton. The coin uses the Godot icon as its sprite. If you want fruit sprites instead, grab our &lt;a href="https://codingcush.com/catch-the-fruit-free-art-pack-for-the-godot-4-hindi-course" rel="noopener noreferrer"&gt;free Catch the Fruit art pack&lt;/a&gt;. The player walks with the arrow keys, with the movement script from &lt;a href="https://codingcush.com/how-to-move-a-character-in-godot-4-gdscript" rel="noopener noreferrer"&gt;how to move a character in Godot 4 with GDScript&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: give the coin a signal of its own
&lt;/h2&gt;

&lt;p&gt;Attach a script to the Coin node and write this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Area2D

signal collected

func _ready():
    body_entered.connect(_on_body_entered)

func collect():
    collected.emit()

func _on_body_entered(_body):
    collected.emit()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The line signal collected defines a new signal. Name signals with a past-tense verb, because a signal reports something that just happened: pressed, collected, died. The _ready function connects the Area2D's built-in body_entered signal to a function on the same script, so walking into the coin triggers _on_body_entered, which calls collected.emit(). The collect() function does the same thing on demand, so you can test the signal from the button.&lt;/p&gt;

&lt;p&gt;Notice what the coin does not do. It never touches the score, and it never looks for the label. It only announces that it was collected. Drop it into any scene, connect its signal, and it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: connect the signal in code
&lt;/h2&gt;

&lt;p&gt;Now attach a script to the Main node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Node2D

var score = 0

func _ready():
    $Coin.collected.connect(_on_coin_collected)

func _on_coin_collected():
    score += 1
    $ScoreLabel.text = "Score: " + str(score)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The connection happens in _ready, which Godot calls once when the node enters the scene. The line $Coin.collected.connect(_on_coin_collected) reads almost like English: connect the Coin's collected signal to this script's _on_coin_collected function. From then on, every time the coin emits collected, Godot calls that function, which adds one to score and writes the new total into the label. Tested headless in Godot 4.3: one collect() call moved the score from 0 to 1.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe74krtyvcr4577ykyahv.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe74krtyvcr4577ykyahv.png" alt="The Godot 4 editor with the CollectButton selected and the Signals dock open on the right, listing the Button signals button_down, button_up, pressed and toggled" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Signals dock in the Godot 4 editor, showing the CollectButton's signals. pressed() is the one this post uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  The no-code way: connect a button in the editor
&lt;/h2&gt;

&lt;p&gt;Code is not the only way to connect a signal. Select the CollectButton, open the Node tab at the top right of the editor, and click Signals. The dock lists every signal the button can send. Double-click it, and the editor offers to create a receiver function on a node with a script. Accept, and Godot writes the function for you, named _on_button_pressed by convention.&lt;/p&gt;

&lt;p&gt;Here is the same idea from Godot's own getting-started tutorial, where a button starts and stops a spinning sprite:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Sprite2D

var speed = 400.0
var angular_speed = PI

func _process(delta):
    rotation += angular_speed * delta
    var velocity = Vector2.UP.rotated(rotation) * speed
    position += velocity * delta

func _on_button_pressed():
    set_process(not is_processing())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each press calls _on_button_pressed, which flips processing on or off with set_process(not is_processing()). The editor connection and the code connection do the same job, and the editor one saves you typing the connect line. Use the editor for buttons you build by hand, and code for nodes you spawn from a script. &lt;a href="https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html" rel="noopener noreferrer"&gt;Godot's own signals tutorial&lt;/a&gt; walks through this button example step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Signals you will meet every week
&lt;/h2&gt;

&lt;p&gt;Most of your signal work will use a small set of built-ins:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Node&lt;/th&gt;
&lt;th&gt;Signal&lt;/th&gt;
&lt;th&gt;When it fires&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Button&lt;/td&gt;
&lt;td&gt;pressed()&lt;/td&gt;
&lt;td&gt;The player clicks or taps the button&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Button&lt;/td&gt;
&lt;td&gt;toggled(toggled_on)&lt;/td&gt;
&lt;td&gt;A toggle button switches state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timer&lt;/td&gt;
&lt;td&gt;timeout()&lt;/td&gt;
&lt;td&gt;The timer runs out&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Area2D&lt;/td&gt;
&lt;td&gt;body_entered(body)&lt;/td&gt;
&lt;td&gt;A physics body walks into the area&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CanvasItem&lt;/td&gt;
&lt;td&gt;visibility_changed()&lt;/td&gt;
&lt;td&gt;The node is shown or hidden&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Timer one is worth remembering on its own, because timers show up everywhere: skill cooldowns, weapon reloads, enemy spawn waves. Connect timeout in _ready, the same way the coin connected body_entered.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a signal needs to carry a number
&lt;/h2&gt;

&lt;p&gt;Sometimes the news is not enough, and the listener needs a value with it. A health bar does not just need to know that health changed. It needs the new number. A signal can declare arguments for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Node2D

signal health_depleted
signal health_changed(old_value, new_value)

var health = 10

func take_damage(amount):
    var old_health = health
    health -= amount
    health_changed.emit(old_health, health)
    if health &amp;lt;= 0:
        health_depleted.emit()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The signal health_changed(old_value, new_value) promises two numbers, and the emit call passes them in the same order. The receiver must accept two parameters, in the same order, or Godot complains. &lt;a href="https://docs.godotengine.org/en/stable/classes/class_signal.html" rel="noopener noreferrer"&gt;The Signal class reference&lt;/a&gt; lists everything else you can do with a signal, including checking whether it is connected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five mistakes that stop signals working
&lt;/h2&gt;

&lt;p&gt;Most broken signals come from one of five small slips. First, the connect line sits in _process instead of _ready, so it runs sixty times a second and the function fires sixty times per signal. Connect once, in _ready. Second, get_node has the wrong name, because the node was renamed in the editor and the script still uses the old one. Third, a typo in the signal name or the function name. The editor's Signals dock shows the exact spelling, so copy it from there. Fourth, the signal is emitted before anything connects to it. Nothing happens, and no error appears. Fifth, the same signal is connected twice, so the function runs twice per emit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I have to use signals, or can I call functions directly?
&lt;/h3&gt;

&lt;p&gt;You can call functions directly, and for two nodes that always work together, that is fine. Signals earn their keep when the sender should not know who is listening.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can one signal call more than one function?
&lt;/h3&gt;

&lt;p&gt;Yes. Connect as many listeners as you like to the same signal, and Godot calls each one when it fires. A coin's collected signal can update the score, play a sound, and spawn a sparkle, all from one emit.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between a signal and a function call?
&lt;/h3&gt;

&lt;p&gt;A function call names the receiver. A signal does not. With a call, the caller must hold a reference to the receiver. With a signal, neither side knows the other exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do signals work the same in every Godot 4 version?
&lt;/h3&gt;

&lt;p&gt;The basics here work in every Godot 4 release. Signals became a first-class type in Godot 4.0, and the code in this post was run in Godot 4.3. Godot 3 uses different syntax for the same idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it yourself, then keep going
&lt;/h2&gt;

&lt;p&gt;Now it is your turn. Add a second coin to the scene and connect its signal to the same function, then add a Timer that hides the coin for a few seconds. If you want a bigger playground, wire the coin signal into a real game: our &lt;a href="https://codingcush.com/snake-game-free-art-pack" rel="noopener noreferrer"&gt;Snake game art pack&lt;/a&gt; gives you the sprites, and every food pickup in Snake is a signal waiting to happen. The video version of this lesson is in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>gdscript</category>
      <category>gamedev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Move a Character in Godot 4 with GDScript</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Wed, 02 Dec 2026 05:25:17 +0000</pubDate>
      <link>https://dev.to/kushkrg/how-to-move-a-character-in-godot-4-with-gdscript-36o2</link>
      <guid>https://dev.to/kushkrg/how-to-move-a-character-in-godot-4-with-gdscript-36o2</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/how-to-move-a-character-in-godot-4-gdscript" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You move a character in Godot 4 by giving it a CharacterBody2D node and a short GDScript that reads the keys every physics frame and calls move_and_slide(). That is the whole trick, and the script is only eight lines long. The rest of this post answers the five questions that trip up nearly every beginner: which node to use, where the code goes, how Godot reads the keyboard, why characters walk through walls, and how the same code turns into a platformer. Everything here targets Godot 4.3, and every line of code was run first. If you prefer to watch the lesson first, the video version sits in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question 1: which node should the player be?
&lt;/h2&gt;

&lt;p&gt;Godot gives you several nodes that can move. A plain Node2D has no collision, so your character would glide through every wall. An Area2D can detect overlaps, but it cannot push back against a wall. A CharacterBody2D is built for this job: it detects collisions when it moves, and your code decides what happens next.&lt;/p&gt;

&lt;p&gt;Make a new scene and add a CharacterBody2D as the root. Name it Player. Then give it two children. A Sprite2D shows the character on screen, and a CollisionShape2D gives it a solid body the physics engine can bump into. For the shape, pick a RectangleShape2D sized to cover the sprite. If you have no sprite yet, our &lt;a href="https://codingcush.com/snake-game-free-art-pack" rel="noopener noreferrer"&gt;Snake game art pack&lt;/a&gt; has a ready-made set you can drop straight in.&lt;/p&gt;

&lt;p&gt;One setting matters first. In the Inspector, find Motion Mode on the CharacterBody2D. The default is Grounded, right for a platformer. For a top-down game, set it to Floating, which tells Godot every collision is a wall.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question 2: where does the movement code live?
&lt;/h2&gt;

&lt;p&gt;Attach a script to the Player node and write this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends CharacterBody2D

@export var speed = 300.0

func _physics_process(_delta):
    var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    velocity = direction * speed
    move_and_slide()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three lines do the work. Input.get_vector reads the four arrow keys and returns a direction, like (1, 0) for right or (0, -1) for up. Multiplying by speed turns it into a velocity in pixels per second, so 300 means the character crosses 300 pixels in one second. Then move_and_slide() moves the body and slides it along anything it hits, instead of stopping dead.&lt;/p&gt;

&lt;p&gt;Notice the function name: _physics_process, not _process. Godot calls _physics_process 60 times a second by default, while _process runs once per rendered frame, which changes with the frame rate. Movement belongs in _physics_process because physics needs a steady beat. Code in _process still moves the character, but the speed changes whenever the frame rate does.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5q06mcy5c4xfsbx5bwew.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5q06mcy5c4xfsbx5bwew.png" alt="The Godot 4 script editor showing player.gd, the movement script from this tutorial, with extends CharacterBody2D, an exported speed of 300.0, and _physics_process calling Input.get_vector and move_and_slide" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The movement script open in the Godot 4 script editor. Eight lines, and the player already walks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question 3: how does Godot read the arrow keys?
&lt;/h2&gt;

&lt;p&gt;The ui_left, ui_right, ui_up and ui_down names in the script are input actions, and they already exist. Every Godot project ships with built-in ui_ actions, and the arrow keys are wired to them by default. That is why the script works with no setup: press an arrow key, and Input.get_vector returns the matching direction.&lt;/p&gt;

&lt;p&gt;Input.get_vector takes four action names in this order: left, right, up, down. It returns a Vector2, and it normalises the result, so pressing up and right together gives a diagonal of length 1, not 1.41. Your character moves at the same speed in every direction.&lt;/p&gt;

&lt;p&gt;For your own keys, open Project, then Project Settings, then the Input Map tab, and add an action. Name it move_left, click the plus button, and press the key you want. Then swap the names in the script. The rest stays the same: the script talks about what the player wants, and the Input Map decides which key means it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question 4: why does my character walk through walls?
&lt;/h2&gt;

&lt;p&gt;Three ways to move a body exist, and only two respect walls:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;When to use it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;move_and_slide()&lt;/td&gt;
&lt;td&gt;Moves the body and slides it along anything it hits&lt;/td&gt;
&lt;td&gt;Players, enemies, anything that walks around&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;move_and_collide()&lt;/td&gt;
&lt;td&gt;Moves the body and stops at the first thing it hits&lt;/td&gt;
&lt;td&gt;Bullets, or when you want to code the bounce yourself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;position += velocity * delta&lt;/td&gt;
&lt;td&gt;Teleports the body a little each frame&lt;/td&gt;
&lt;td&gt;Never for a physics body; it skips collision checks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Setting position directly is the usual culprit. It looks like it works, because the sprite moves, but the physics engine never gets a say. The body jumps from one spot to the next without checking what stands between them, so thin walls get skipped. The official &lt;a href="https://docs.godotengine.org/en/stable/tutorials/physics/using_character_body_2d.html" rel="noopener noreferrer"&gt;CharacterBody2D documentation&lt;/a&gt; says the same in its first section: do not set position directly, use move_and_collide or move_and_slide instead.&lt;/p&gt;

&lt;p&gt;A wall needs the same two parts: a StaticBody2D with a CollisionShape2D, the same way you built the player. A sprite alone is only a picture; without the body and its shape, the wall is decoration and the player walks straight past it. The floor works the same way, with a wide rectangle along the bottom of the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question 5: can the same script run a platformer?
&lt;/h2&gt;

&lt;p&gt;Yes, with two changes: gravity and a jump. A platformer moves left and right, and falls the rest of the time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends CharacterBody2D

var speed = 300.0
var jump_speed = -400.0

func _physics_process(delta):
    velocity += get_gravity() * delta
    if Input.is_action_just_pressed("ui_accept") and is_on_floor():
        velocity.y = jump_speed
    var direction = Input.get_axis("ui_left", "ui_right")
    velocity.x = direction * speed
    move_and_slide()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gravity comes from get_gravity(), which returns the value in Project Settings, 980 pixels per second squared by default. Adding it to velocity every frame makes the character fall faster the longer it is in the air, which is how a jump gets its arc. The jump line fires only when two things are true at once: the player just pressed the key, and is_on_floor() says the body is standing on something. Without that check, the player could jump again in mid-air, forever.&lt;/p&gt;

&lt;p&gt;Two details are easy to miss. First, jump_speed is negative because in Godot, up is negative Y, so -400 pushes the character up. Second, the key here is ui_accept, the built-in action bound to Space and Enter, so this version also runs with no Input Map setup. If you want a full game built on these ideas, the official &lt;a href="https://docs.godotengine.org/en/stable/getting_started/first_2d_game/index.html" rel="noopener noreferrer"&gt;Your first 2D game tutorial in the Godot docs&lt;/a&gt; builds a small dodge-the-enemies game step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five mistakes that stop a character moving
&lt;/h2&gt;

&lt;p&gt;Most broken movement comes from one of five small slips. First, the script is attached to the wrong node, usually the Sprite2D instead of the CharacterBody2D, so move_and_slide runs on a node that has no velocity. Second, the CollisionShape2D has no shape assigned, so the body has nothing to collide with. Third, the code sits in _process instead of _physics_process, and the character stutters or runs at a different speed on every machine. Fourth, the script sets position directly, which looks fine in an empty room and breaks the moment a wall appears. Fifth, an input action name is typed wrong, so get_vector quietly returns (0, 0). When nothing moves at all, check those five in order before rewriting anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I need to create input actions before this works?
&lt;/h3&gt;

&lt;p&gt;No. The ui_left, ui_right, ui_up and ui_down actions are built into every project, and the arrow keys are already bound to them. Create your own only when you want different keys, like WASD, or a gamepad.&lt;/p&gt;

&lt;h3&gt;
  
  
  What speed should I use?
&lt;/h3&gt;

&lt;p&gt;Start at 300. It is fast enough to feel responsive and slow enough to control in a 640 by 360 viewport. Small rooms want 200, open maps can take 400. The &lt;a class="mentioned-user" href="https://dev.to/export"&gt;@export&lt;/a&gt; in front of speed puts a slider in the Inspector, so you can tune it while the game runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is my character faster when moving diagonally?
&lt;/h3&gt;

&lt;p&gt;It should not be, if you use Input.get_vector, because the function normalises the direction. If you read the keys separately and add the directions yourself, the diagonal becomes about 1.41, so normalise it with direction.normalized() or switch to get_vector.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does this work in 3D too?
&lt;/h3&gt;

&lt;p&gt;The idea is the same, but the node is CharacterBody3D and the direction is a Vector3. The official docs cover both on the same CharacterBody2D/3D page, and the pattern is identical: read input, set velocity, call move_and_slide.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to build next
&lt;/h2&gt;

&lt;p&gt;You now have a character that walks, slides along walls, and jumps. Give it something to do. Add a second wall and a gap to jump over, then swap the plain square sprite for a real character from our &lt;a href="https://codingcush.com/catch-the-fruit-free-art-pack-for-the-godot-4-hindi-course" rel="noopener noreferrer"&gt;free Catch the Fruit art pack&lt;/a&gt;. If you get stuck, the video version of this lesson is in the &lt;a href="https://youtube.com/playlist?list=PLdvQ6Wg5aND0" rel="noopener noreferrer"&gt;Godot 4 Full Course in Hindi, free on YouTube&lt;/a&gt;, and every episode is listed on our &lt;a href="https://codingcush.com/godot-4-hindi-course" rel="noopener noreferrer"&gt;Godot 4 Hindi course page&lt;/a&gt;. Next lesson, we will give this character an animation, so it walks instead of glides.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>gdscript</category>
      <category>gamedev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What Is an AI Agent? Explained Simply for Beginners</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Tue, 01 Dec 2026 06:21:31 +0000</pubDate>
      <link>https://dev.to/kushkrg/what-is-an-ai-agent-explained-simply-for-beginners-5efp</link>
      <guid>https://dev.to/kushkrg/what-is-an-ai-agent-explained-simply-for-beginners-5efp</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/what-is-an-ai-agent-explained-simply" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An AI agent is software that takes a goal from you, works out the steps, and does them by itself, using tools such as web search, a calendar, or a messaging app. A chatbot waits for your next message and answers it. An agent keeps going until the job is done, and changes its plan when a step fails. This post explains the sense-think-act loop, how an agent differs from a chatbot, and what agents can and cannot do.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Loop That Makes an Agent an Agent
&lt;/h2&gt;

&lt;p&gt;Every agent runs the same loop. First it senses: it reads your goal and what it knows so far. Then it thinks: it picks the next action, usually by choosing a tool. Then it acts: it runs the tool and reads the result. Then it loops back and senses again, until the goal is done or it runs out of steps. That loop is the whole trick. Under it sits a large language model, which picks the tools. For the background, read our guide to &lt;a href="https://codingcush.com/what-is-machine-learning-explained-simply" rel="noopener noreferrer"&gt;machine learning, explained simply&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Take a small goal: "Tell me the weather in Jaipur and message it to me." The agent calls a weather tool, reads the result ("sunny, 28C"), then calls the messaging tool. Two tools, two rounds of the loop, job done. A chatbot would just answer in the chat and stop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 1: AI Agents Think Like Humans Do
&lt;/h2&gt;

&lt;p&gt;When an agent writes a neat plan in perfect English, it feels like a person thinking out loud. The fact is duller, and more useful: an agent does not understand anything the way you do. Under the surface it is a language model predicting the most likely next words, plus tools it can call. It has no beliefs, no curiosity, and no idea what rain in Jaipur feels like. It can still be useful, because predicting the next step well is often enough, but it can also sound completely confident while being completely wrong. Treat what it does as a draft.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 2: An Agent Is Just a Smarter Chatbot
&lt;/h2&gt;

&lt;p&gt;People mix up the two words, and that causes most of the disappointment. A chatbot is a conversation: you type, it replies, you type again. An agent is a worker: you give it a goal, and it takes actions in your apps until the goal is done. The difference is not how smart the model is, but whether the software is allowed to act. &lt;a href="https://www.ibm.com/think/topics/ai-agents" rel="noopener noreferrer"&gt;IBM describes an AI agent as a system that performs tasks on its own&lt;/a&gt; by designing workflows with the tools it has, not just writing replies. A chatbot without tools or memory can only reach short term goals.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Chatbot&lt;/th&gt;
&lt;th&gt;AI agent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;You give it&lt;/td&gt;
&lt;td&gt;One message&lt;/td&gt;
&lt;td&gt;One goal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;It does&lt;/td&gt;
&lt;td&gt;Writes replies&lt;/td&gt;
&lt;td&gt;Acts with tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory&lt;/td&gt;
&lt;td&gt;This chat only&lt;/td&gt;
&lt;td&gt;Notes across steps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;It stops&lt;/td&gt;
&lt;td&gt;After each reply&lt;/td&gt;
&lt;td&gt;When the goal is done&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Typical mistake&lt;/td&gt;
&lt;td&gt;Forgetting context&lt;/td&gt;
&lt;td&gt;Wrong confident action&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If the chatbot side is still fuzzy, read &lt;a href="https://codingcush.com/what-is-a-chatbot-explained-simply" rel="noopener noreferrer"&gt;what a chatbot actually is&lt;/a&gt; first. To see a real agent, look at &lt;a href="https://codingcush.com/deepseek-harness-explained-open-source-ai-agent" rel="noopener noreferrer"&gt;DeepSeek Harness, an open-source AI agent you can run yourself&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkmchpiey5q72t92q0ftx.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkmchpiey5q72t92q0ftx.png" alt="Screenshot of the IBM page 'What are AI agents?' on ibm.com, showing the page heading and a photo of people working" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The IBM page "What are AI agents?", which defines an agent as a system that works through tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 3: Agents Work on Their Own, So You Can Walk Away
&lt;/h2&gt;

&lt;p&gt;Demo videos make this myth look true: one sentence, and the agent books, searches, writes, and sends. Real life is messier: agents get stuck, pick the wrong tool, or loop forever on a failing step. So start simple, and only add complexity when the simple version fails. &lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Anthropic's guide to building effective agents&lt;/a&gt; puts it plainly: find the simplest solution possible first, since agentic systems trade speed and cost for better task performance. So stay in the loop: set a clear goal and a step limit, check the important results, and keep the agent away from anything you cannot undo.&lt;/p&gt;

&lt;h2&gt;
  
  
  See the Loop in a Few Lines of Python
&lt;/h2&gt;

&lt;p&gt;Talking about the loop is one thing. Seeing it run is better. The sketch below is illustrative: not a real agent framework, and it calls no real language model. It shows the loop with two pretend tools. The three comments, SENSE, THINK, and ACT, are the whole idea.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Illustrative sketch of the sense-think-act loop.
tools = {
    "check_weather": lambda city: "sunny, 28C in " + city,
    "send_message": lambda text: "sent: " + text,
}

goal = "Jaipur weather, then message it"
plan = [("check_weather", "Jaipur"), ("send_message", "sunny, 28C in Jaipur")]

for step, (action, argument) in enumerate(plan, 1):
    # SENSE: read the goal
    print("Step", step, "- sensing:", goal)
    # THINK: pick the next tool
    # ACT: run the tool
    result = tools[action](argument)
    print("Acted with", action, "-&amp;gt;", result)
print("Done in", len(plan), "steps.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with python3 and you get this exact output, verified on 2026-12-01:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1 - sensing: Jaipur weather, then message it
Acted with check_weather -&amp;gt; sunny, 28C in Jaipur
Step 2 - sensing: Jaipur weather, then message it
Acted with send_message -&amp;gt; sent: sunny, 28C in Jaipur
Done in 2 steps.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what the sketch never does: decide anything clever, because the plan is a fixed list. A real agent replaces that fixed list with a language model that reads the goal and the last result, then picks the next tool. That one change turns a fixed script into an agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 4: Agents Will Replace Developers
&lt;/h2&gt;

&lt;p&gt;This myth worries beginners most, so here is the direct answer: no, not in the way people fear. Agents are good at the routine middle of a task: writing boilerplate, searching docs, running tests, fixing a small error. They are bad at the parts that make a developer a developer: deciding what to build, understanding what a user wants, and taking responsibility when things break. A developer who uses an agent well gets faster, because the agent types while the developer thinks. One who hands over the whole job gets code that looks finished and fails in hidden ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 5: Agents Are Safe Because They Are Smart
&lt;/h2&gt;

&lt;p&gt;Smart and safe are different words, and mixing them up is how things break. An agent that can send messages can send the wrong message. One that can read your files can read the wrong file. One that can run commands can run a harmful one, politely and quickly, unless you set limits first. Safety comes from boring rules, not intelligence: few permissions, no money or deletions, a step limit, and a human reading the log.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes Beginners Make with Agents
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;You give it a vague goal.&lt;/strong&gt; "Make my project better" is a wish, not a goal. Write one sentence with a clear result instead: "List the three slowest pages with their load times."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You give it no limits.&lt;/strong&gt; With no step or spending limit, an agent can loop for a long time on a task it cannot finish. Set a maximum number of steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You trust the first answer.&lt;/strong&gt; Agents sound confident even when they are wrong. Ask for the source, and check the result yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You hand over too much access.&lt;/strong&gt; A research agent does not need permission to delete files or send emails. Give one permission at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You expect it to work first time.&lt;/strong&gt; Most agent runs need a retry or a clearer prompt. Split big goals into small steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions Beginners Keep Asking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do AI agents think?
&lt;/h3&gt;

&lt;p&gt;No, not the way you think. An agent predicts likely words and picks tools, following the sense-think-act loop. It has no understanding of what it is doing.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between an AI agent and an AI assistant?
&lt;/h3&gt;

&lt;p&gt;An assistant is a helper you talk to in a chat, and it answers or drafts things for you. An agent takes a goal and acts on it with tools, often without you watching every step. So ask one question: does it only reply, or does it also act?&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I build an AI agent without coding?
&lt;/h3&gt;

&lt;p&gt;Yes, for simple jobs. Several tools let you connect a language model to apps with clicks instead of code. For anything custom, you will need some Python, and the sketch above is a good place to start.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are AI agents safe to use?
&lt;/h3&gt;

&lt;p&gt;They are safe when you set limits: few permissions, a step limit, and a human checking the results. Never let an untested agent touch money, private data, or anything you cannot undo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Turn: Run the Loop Yourself
&lt;/h2&gt;

&lt;p&gt;Here is a small challenge. Copy the sketch into a file, run it with python3, and watch the loop print its steps. Then change one thing: make the goal about your own city, and add a third pretend tool. Agents are not magic, and they are not people. They are a loop, a model, and a set of tools, and once you see the loop clearly, the myths fall away on their own.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What Is a Tree in Data Structures? Explained with Simple Examples</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Tue, 01 Dec 2026 06:20:40 +0000</pubDate>
      <link>https://dev.to/kushkrg/what-is-a-tree-in-data-structures-explained-with-simple-examples-45d0</link>
      <guid>https://dev.to/kushkrg/what-is-a-tree-in-data-structures-explained-with-simple-examples-45d0</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/what-is-a-tree-in-data-structures-explained" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A tree is a way of storing data in branches instead of in one long line. Think of a family tree: one item at the top, a few below it, and each of those with its own items underneath. Each box of data is called a node, the lines between boxes are called edges, and the top box is called the root. Trees make finding things fast: one item among thousands, found without checking them all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: finding one name in a pile of ten thousand
&lt;/h2&gt;

&lt;p&gt;Imagine a teacher with ten thousand students on one plain attendance sheet. A parent phones in: "Is my daughter Anaya on the list?" The only way to answer is to start at the top and read every name until you find hers.&lt;/p&gt;

&lt;p&gt;That is the cost of a flat list. An array stores items one after another, and a &lt;a href="https://codingcush.com/linked-list-explained-simply" rel="noopener noreferrer"&gt;linked list, explained simply in our earlier guide&lt;/a&gt;, stores each item with a pointer to the next one. Searching either one means walking the line from the start, because a list only knows "next".&lt;/p&gt;

&lt;p&gt;Can we arrange the same data so each step throws away a big chunk of what is left? Yes, and it looks like a tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: let the data branch
&lt;/h2&gt;

&lt;p&gt;Think about finding a file. You open Documents, then Projects, then website, then images, and there it is. You never open every folder on the disk, because each folder narrows the search.&lt;/p&gt;

&lt;p&gt;A tree does the same thing with data. As the &lt;a href="https://www.programiz.com/dsa/trees" rel="noopener noreferrer"&gt;Programiz guide to the tree data structure&lt;/a&gt; puts it, a tree is a nonlinear hierarchical data structure that consists of nodes connected by edges. Nonlinear means the data is not in one straight line. Here are the words you will keep meeting:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.&lt;/strong&gt; One box of data, holding a value and links to the nodes below it. &lt;strong&gt;Edge.&lt;/strong&gt; The link between two nodes. &lt;strong&gt;Root.&lt;/strong&gt; The topmost node, and the only one with no parent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parent and child.&lt;/strong&gt; The node above is the parent, the one below is the child. Every node except the root has exactly one parent, and there are no loops. Children of one parent are siblings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Leaf.&lt;/strong&gt; A node with no children, the end of a branch. &lt;strong&gt;Height and depth.&lt;/strong&gt; Depth is the edges from a node to the root. Height is the longest path from a node down to a leaf.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tree you will meet first: the binary search tree
&lt;/h2&gt;

&lt;p&gt;The most common tree in beginner courses is the binary search tree, or BST. A binary tree is a tree where each node has at most two children. A BST adds one sorting rule at every node: all values in the left subtree are smaller than the node, and all values in the right subtree are larger.&lt;/p&gt;

&lt;p&gt;That rule turns searching into higher or lower. Start at the root. Smaller? Go left. Larger? Go right. Match? Found it. Each step throws away half of what is left. The Programiz guide says a BST can search in O(log n) time, and our guide to &lt;a href="https://codingcush.com/big-o-notation-explained-simply" rel="noopener noreferrer"&gt;Big O notation, explained simply&lt;/a&gt;, unpacks what that means.&lt;/p&gt;

&lt;h2&gt;
  
  
  One working example: build a small BST in Python
&lt;/h2&gt;

&lt;p&gt;Enough theory. Here is a complete BST in Python, with insert, search, and an inorder print that shows the values in sorted order. It follows the steps the Programiz BST guide describes, and it was run on this machine, so the output below is real.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

def insert(node, key):
    # Empty spot: create the new node
    if node is None:
        return Node(key)
    # Smaller goes left, larger goes right
    if key &amp;lt; node.key:
        node.left = insert(node.left, key)
    elif key &amp;gt; node.key:
        node.right = insert(node.right, key)
    return node

def search(node, key):
    # Empty spot: the value is not here
    if node is None:
        return None
    if key == node.key:
        return node
    if key &amp;lt; node.key:
        return search(node.left, key)
    return search(node.right, key)

def inorder(root):
    if root is not None:
        inorder(root.left)
        print(root.key, end=" ")
        inorder(root.right)

root = None
for number in [50, 30, 70, 20, 40, 60, 80]:
    root = insert(root, number)

print("Inorder traversal (sorted order):")
inorder(root)
print()

for target in [40, 90]:
    found = search(root, target)
    if found is not None:
        print(target, "found in the tree")
    else:
        print(target, "not found in the tree")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each Node holds one value plus left and right links. Insert walks down comparing as it goes: smaller goes left, larger goes right, and an empty spot gets the new node. Insert and search call themselves to go down a level at a time: that is recursion, and our guide to &lt;a href="https://codingcush.com/recursion-explained-with-examples" rel="noopener noreferrer"&gt;recursion, explained with examples&lt;/a&gt;, covers it in detail.&lt;/p&gt;

&lt;p&gt;The inorder print visits the left subtree, then the node, then the right subtree. Smaller values always sit on the left, so the numbers print in sorted order. Here is the real output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Inorder traversal (sorted order):
20 30 40 50 60 70 80
40 found in the tree
90 not found in the tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Trace the search for 40. Start at the root, 50. 40 is smaller, so go left to 30. 40 is larger, so go right: three comparisons. The search for 90 walks down the right side, 50, 70, 80, then hits an empty spot.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3lun3g60ls5o24m0abu7.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3lun3g60ls5o24m0abu7.png" alt="Screenshot of the Tree Data Structure page on Programiz, showing the definition of a tree and the start of a tree diagram with numbered nodes" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Programiz Tree Data Structure page, where this post's definition and tree diagram come from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tree vs linked list: a quick comparison
&lt;/h2&gt;

&lt;p&gt;Same nodes, different shape:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Binary search tree&lt;/th&gt;
&lt;th&gt;Linked list&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Shape&lt;/td&gt;
&lt;td&gt;Branches, like folders&lt;/td&gt;
&lt;td&gt;One straight line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Finding one item&lt;/td&gt;
&lt;td&gt;About O(log n) when balanced&lt;/td&gt;
&lt;td&gt;O(n), walk from the start&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inserting a new item&lt;/td&gt;
&lt;td&gt;Walk down to the spot&lt;/td&gt;
&lt;td&gt;Fast at the right spot&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Staying in sorted order&lt;/td&gt;
&lt;td&gt;Built in by the sorting rule&lt;/td&gt;
&lt;td&gt;Extra work on every insert&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory per item&lt;/td&gt;
&lt;td&gt;Two links per node&lt;/td&gt;
&lt;td&gt;One link per node&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Searching and sorted data&lt;/td&gt;
&lt;td&gt;Simple queues of items&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Neither one wins everywhere. A list is simpler for adding and removing at the ends. A tree wins when you search again and again.&lt;/p&gt;

&lt;p&gt;Trees also run your day quietly. Your file system is a tree, a web page is a DOM tree, databases index with B-trees, routers use tries, and compilers build syntax trees. The &lt;a href="https://en.wikipedia.org/wiki/Tree_(data_structure)" rel="noopener noreferrer"&gt;Wikipedia article on the tree data structure&lt;/a&gt; lists these classic uses and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes and troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Forgetting the sorting rule.&lt;/strong&gt; Inserting values without comparing builds a plain binary tree that only looks like a BST, and search then gives wrong answers. Fix: never attach a node without walking down with comparisons first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building a lopsided tree.&lt;/strong&gt; Insert 1, 2, 3, 4, 5 in order and each node goes right, right, right, so the tree becomes a line in disguise. Fix: insert in a mixed order; real systems use self balancing trees like AVL trees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting the empty tree.&lt;/strong&gt; Searching an empty tree, or past a leaf, reaches a None node, and reading node.key there crashes. Fix: check for None first, as the search function above does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading inorder output as the shape.&lt;/strong&gt; Inorder shows sorted values, not the shape. Two different trees can print the same sorted line. Fix: sketch the tree on paper from the insert order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick answers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is a tree the same as a binary tree?
&lt;/h3&gt;

&lt;p&gt;No. A tree is the general idea: nodes joined by edges in a branching shape. A binary tree is one kind, where each node has at most two children. A binary search tree adds the sorting rule: smaller on the left, larger on the right.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between a tree and a linked list?
&lt;/h3&gt;

&lt;p&gt;A linked list is a line: each node points to the next one, so finding an item means walking from the start. A tree branches, so each step throws away a whole section. Lists are simpler; trees search faster.&lt;/p&gt;

&lt;h3&gt;
  
  
  When should I use a tree?
&lt;/h3&gt;

&lt;p&gt;Use one when you search often, data keeps arriving, and you want results in sorted order. That covers phone books, file systems, database indexes, and autocomplete. If you only add items at the end and read them in order, a list is enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  A tiny quiz before you go
&lt;/h2&gt;

&lt;p&gt;Three quick questions to check what stuck. Guess first, then check.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; In a binary search tree with root 50, where does 20 go, left or right? Left, because 20 is smaller than 50, and smaller values go left.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Which node has no parent? The root. Every other node has exactly one parent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; You insert 1, 2, 3, 4, 5 in order into an empty BST. What shape do you get? A straight line leaning right, as slow to search as a list. That is why balanced trees matter.&lt;/p&gt;

&lt;p&gt;Next step: run the Python example, then change the insert list to your own numbers. Then draw the tree those numbers build, one insert at a time. Once the shape feels natural, try the AVL tree, which stays balanced no matter what order the data arrives in.&lt;/p&gt;

</description>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Is Composer in PHP? A Beginner's Guide</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Tue, 01 Dec 2026 06:19:49 +0000</pubDate>
      <link>https://dev.to/kushkrg/what-is-composer-in-php-a-beginners-guide-42ao</link>
      <guid>https://dev.to/kushkrg/what-is-composer-in-php-a-beginners-guide-42ao</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/what-is-composer-in-php-explained-simply" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Composer is the tool that installs and manages libraries for your PHP projects. You tell it which packages your project needs in a small file called composer.json, and it downloads the right versions, sorts out their own dependencies, and gives you one file to include so every class is ready to use. In this guide we will build one tiny project together, a notes app that saves notes and logs each one with Monolog.&lt;/p&gt;

&lt;h2&gt;
  
  
  The project we will build
&lt;/h2&gt;

&lt;p&gt;Reading about a tool is one thing. Using it on a real project is how it clicks, so this guide hangs on one small app. Our notes app does three simple jobs: it takes a note from the command line, appends it to notes.txt, and writes a log line to notes.log. Instead of writing our own logger, we will borrow Monolog, the logging library the official Composer docs use in their own getting started example.&lt;/p&gt;

&lt;p&gt;The plan is short: install Composer, ask it for Monolog, write notes.php, run it twice, and read the files it creates. Nothing here needs a web server, a database, or a framework. If PHP itself is still new to you, our guide to &lt;a href="https://codingcush.com/what-is-php-explained-simply" rel="noopener noreferrer"&gt;what PHP is, explained simply&lt;/a&gt; is a good warm up.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, get Composer onto your machine
&lt;/h2&gt;

&lt;p&gt;Composer is a single program file, a PHAR archive, that runs with PHP. It needs PHP 7.2.5 or newer, and the current release is Composer 2.11.3. Check your version first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the four commands from the official Composer download page. The long second line checks the installer against its published SHA-384 hash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php -r &lt;span class="s2"&gt;"copy('https://getcomposer.org/installer', 'composer-setup.php');"&lt;/span&gt;
php -r &lt;span class="s2"&gt;"if (hash_file('sha384', 'composer-setup.php') === 'c8c37e2f8c0204c6b378c28a7894181507c6fd0d4b2d84eea3afa2c0d53b5da2443a7b202cc6134ae01e73d1a32b93a4') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"&lt;/span&gt;
php composer-setup.php
php -r &lt;span class="s2"&gt;"unlink('composer-setup.php');"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The installer creates composer.phar in the current folder. Run it once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php composer.phar -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Composer version 2.11.3 2026-11-24 10:14:18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Typing &lt;code&gt;php composer.phar&lt;/code&gt; every time gets old, so most developers move the file onto their PATH and call it plain &lt;code&gt;composer&lt;/code&gt;; the official &lt;a href="https://getcomposer.org/doc/00-intro.md" rel="noopener noreferrer"&gt;Introduction chapter&lt;/a&gt; shows that step for each system. From here on I will write &lt;code&gt;composer&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  One command installs Monolog
&lt;/h2&gt;

&lt;p&gt;Make a folder for the project and step inside it. Then ask Composer for the package from Packagist, the main public library of PHP packages. The name is its vendor name and project name joined with a slash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir notes-app
&lt;span class="nb"&gt;cd&lt;/span&gt; notes-app
composer require monolog/monolog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Composer prints a short progress report, then a line like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Using version ^3.13 for monolog/monolog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three new things now sit in your folder. First, composer.json, the shopping list, and the only file you ever edit by hand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"require"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"monolog/monolog"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"^3.13"&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 &lt;code&gt;require&lt;/code&gt; key lists the packages your project needs. The version &lt;code&gt;^3.13&lt;/code&gt; means any 3.x release from 3.13 upwards, but never 4.0. Second, composer.lock, the exact receipt, recording the precise version of every package installed, so a teammate who clones your project gets the identical code. Commit it to git. Third, the vendor folder, where the downloaded code lives, including vendor/autoload.php. Include that one file and every class is ready to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composer or the old copy paste way?
&lt;/h2&gt;

&lt;p&gt;Before Composer, PHP developers downloaded library zip files by hand and wrote long require lists at the top of every script. It worked until one library needed another, which needed a third:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;Copy paste by hand&lt;/th&gt;
&lt;th&gt;With Composer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Adding a library&lt;/td&gt;
&lt;td&gt;Download the zip, unzip it, guess the folder&lt;/td&gt;
&lt;td&gt;One command: composer require vendor/package&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Library needs another library&lt;/td&gt;
&lt;td&gt;You chase the chain yourself&lt;/td&gt;
&lt;td&gt;Composer resolves it and installs the whole chain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Updating everything&lt;/td&gt;
&lt;td&gt;Repeat the whole manual job&lt;/td&gt;
&lt;td&gt;One command: composer update&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loading the classes&lt;/td&gt;
&lt;td&gt;A pile of require lines in every file&lt;/td&gt;
&lt;td&gt;One line: require vendor/autoload.php&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Now write the notes script
&lt;/h2&gt;

&lt;p&gt;Create notes.php in the project folder. It uses Monolog through the autoloader, so there is no include path to fight with. If classes and objects still feel new, read our guide to &lt;a href="https://codingcush.com/php-oop-explained-classes-objects-beginners" rel="noopener noreferrer"&gt;PHP classes and objects explained for beginners&lt;/a&gt; first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Monolog&lt;/span&gt;\&lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Monolog&lt;/span&gt;\&lt;span class="nc"&gt;Handler&lt;/span&gt;\&lt;span class="nc"&gt;StreamHandler&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$log&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;Logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'notes'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$log&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;pushHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StreamHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/notes.log'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;INFO&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="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$argv&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="o"&gt;??&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Usage: php notes.php \"Buy milk\"\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$log&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'notes.php ran with no note text'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;exit&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="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/notes.txt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;FILE_APPEND&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$log&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Note saved'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'note'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$note&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;echo&lt;/span&gt; &lt;span class="s2"&gt;"Saved: "&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$note&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line pulls in the autoloader, which makes Monolog available. The two &lt;code&gt;use&lt;/code&gt; lines import the Logger class and the StreamHandler class, which writes log lines to a file. Then we create a logger named notes with a StreamHandler that writes to notes.log. The &lt;code&gt;$argv[1] ?? null&lt;/code&gt; line grabs the note text from the command line, falling back to null when the user typed nothing. With no note, it prints a usage hint, logs a warning, and stops with exit code 1. Otherwise it appends the note to notes.txt, logs an info message, and prints a confirmation. That second argument to &lt;code&gt;$log-&amp;gt;info()&lt;/code&gt; is a small &lt;a href="https://codingcush.com/php-arrays-explained" rel="noopener noreferrer"&gt;PHP array&lt;/a&gt; of extra context, which Monolog prints next to the message.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcvu74f4rm6mbbxukq3do.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcvu74f4rm6mbbxukq3do.png" alt="Screenshot of the Basic usage page in the official Composer documentation on getcomposer.org, showing the composer.json setup, the require key, and the monolog/monolog example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The official Composer Basic usage docs page, which walks through the same monolog/monolog example used in this guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it and watch the log grow
&lt;/h2&gt;

&lt;p&gt;Now run the script twice with two different notes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php notes.php &lt;span class="s2"&gt;"Buy milk for chai"&lt;/span&gt;
php notes.php &lt;span class="s2"&gt;"Call Rohan about the PHP project"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Saved: Buy milk for chai
Saved: Call Rohan about the PHP project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now look at the two files the script created: notes.txt holds the notes, one per line, and notes.log holds the diary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2026-12-01T05:18:10.409273+00:00] notes.INFO: Note saved {"note":"Buy milk for chai"} []
[2026-12-01T05:18:10.999449+00:00] notes.INFO: Note saved {"note":"Call Rohan about the PHP project"} []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your dates and times will look different, and that is fine. Each line records the moment, the level, the message, and the note as context. That is the whole point of a logger: when something goes wrong at 2 am, the log tells you what the app did, in order. With no note at all, you get the usage hint instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php notes.php
Usage: php notes.php "Buy milk"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a real project working end to end. The official &lt;a href="https://getcomposer.org/doc/01-basic-usage.md" rel="noopener noreferrer"&gt;Basic usage chapter in the Composer docs&lt;/a&gt; walks the same ground with more detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three commands you will use every week
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;composer install&lt;/code&gt; reads composer.lock and installs the exact versions it lists, so run it after cloning a project. &lt;code&gt;composer update&lt;/code&gt; fetches newer versions that still fit your composer.json and writes a fresh lock file. &lt;code&gt;composer show&lt;/code&gt; lists what is installed. One extra habit: add vendor to your .gitignore file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes and troubleshooting
&lt;/h2&gt;

&lt;p&gt;Here are the ones beginners hit first, and the fix for each.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class not found.&lt;/strong&gt; If PHP says a Monolog class does not exist, the autoloader is missing from your script. Check the first line is &lt;code&gt;require __DIR__ . '/vendor/autoload.php';&lt;/code&gt; and that you run the script from the project folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Could not find package.&lt;/strong&gt; A typo in the package name gives you a blunt error: &lt;code&gt;Could not find package monolog/monlog.&lt;/code&gt; Package names are exact, including the vendor part before the slash. Copy the name from Packagist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Newer package, older PHP.&lt;/strong&gt; Monolog 3 needs PHP 8.1 or newer. If your server still runs PHP 7.4, Composer will refuse the install. Either upgrade PHP, which is the right fix, or ask Composer for an older package line. Never edit version numbers inside vendor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is Composer a package manager like npm?
&lt;/h3&gt;

&lt;p&gt;Close, but not quite. npm installs packages for JavaScript, while Composer manages dependencies per PHP project, in the vendor folder. The idea is the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need Composer for every PHP project?
&lt;/h3&gt;

&lt;p&gt;No. A single file script with no outside libraries does not need it. The moment you use a library, a framework, or a package from Packagist, Composer becomes the sensible way.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between composer.json and composer.lock?
&lt;/h3&gt;

&lt;p&gt;composer.json is your wish list: the packages and version ranges you accept. composer.lock is the exact receipt: the precise version of every package actually installed. You edit the first one, Composer writes the second one, and you commit both to git.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I commit the vendor folder to git?
&lt;/h3&gt;

&lt;p&gt;No. Add vendor to .gitignore. Anyone cloning your project can rebuild it with &lt;code&gt;composer install&lt;/code&gt; and your lock file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn: make the notes app yours
&lt;/h2&gt;

&lt;p&gt;You now have a working project, a real package, and a log file that proves it all works. Give the app one small upgrade today: add a command that lists all saved notes, or one that deletes a line from notes.txt and logs the deletion. Then try a second package: vlucas/phpdotenv lets you store settings in a .env file, and requiring it is the same one command you already ran. And if you are choosing what to build next, our comparison of &lt;a href="https://codingcush.com/laravel-vs-codeigniter-vs-core-php" rel="noopener noreferrer"&gt;Laravel, CodeIgniter and Core PHP compared&lt;/a&gt; will help you pick between a framework and plain PHP with Composer.&lt;/p&gt;

</description>
      <category>php</category>
      <category>composer</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Add Products to Your Shopify Store (Step by Step)</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Mon, 30 Nov 2026 06:01:46 +0000</pubDate>
      <link>https://dev.to/kushkrg/how-to-add-products-to-your-shopify-store-step-by-step-3cc7</link>
      <guid>https://dev.to/kushkrg/how-to-add-products-to-your-shopify-store-step-by-step-3cc7</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/how-to-add-products-to-shopify-store" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Adding a product to Shopify is easier than most beginners expect. If you can fill in a form, you can add a product, because that is almost all it is: one form with a few fields and a Save button at the end. In your Shopify admin, go to Products, click Add product, fill in the title, description, images and price, set the stock, and click Save. Your product goes live in your store the moment its status is Active. This guide walks through each field.&lt;/p&gt;

&lt;p&gt;Our running example is a handmade cotton tote bag that costs $14.99 and comes in two colours, Natural and Forest Green. It is an invented example, not a real store or a real product. We use it because a simple bag shows every field clearly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Product Page Is a Shop Shelf
&lt;/h2&gt;

&lt;p&gt;Before we touch the admin, picture a small physical shop. That picture makes every Shopify field click into place, because Shopify copied the real world almost exactly. The title is the label on the shelf, the description is the shopkeeper's pitch, the photos are the shop window, the price is the price tag, variants are the colours on the rack, inventory is the stockroom count, and status is the Open or Closed sign.&lt;/p&gt;

&lt;p&gt;When a field confuses you, ask which part of the shop it matches. If it matches nothing a shopper would ever see, it is admin-only information, like a tag. If it matches something on the shelf, a shopper will read it, so write it for them.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Shopify field&lt;/th&gt;
&lt;th&gt;The shop equivalent&lt;/th&gt;
&lt;th&gt;Who sees it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Title&lt;/td&gt;
&lt;td&gt;The label on the shelf&lt;/td&gt;
&lt;td&gt;Every shopper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;The shopkeeper's pitch&lt;/td&gt;
&lt;td&gt;Every shopper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Media&lt;/td&gt;
&lt;td&gt;The shop window display&lt;/td&gt;
&lt;td&gt;Every shopper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Price&lt;/td&gt;
&lt;td&gt;The price tag&lt;/td&gt;
&lt;td&gt;Every shopper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Variants&lt;/td&gt;
&lt;td&gt;Colours on the rack&lt;/td&gt;
&lt;td&gt;Every shopper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inventory&lt;/td&gt;
&lt;td&gt;The count in the stockroom&lt;/td&gt;
&lt;td&gt;Only you&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Status&lt;/td&gt;
&lt;td&gt;The Open or Closed sign&lt;/td&gt;
&lt;td&gt;Controls who sees it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tags&lt;/td&gt;
&lt;td&gt;Labels on the stockroom boxes&lt;/td&gt;
&lt;td&gt;Only you&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you are still choosing a platform, read our guide to &lt;a href="https://codingcush.com/wordpress-or-shopify-for-ecommerce" rel="noopener noreferrer"&gt;WordPress or Shopify for ecommerce, compared side by side&lt;/a&gt; before you build your whole catalogue in one place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Your First Product, Step by Step
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Open Products and click Add product.&lt;/strong&gt; In your Shopify admin, click Products in the left menu, then click Add product. The only detail you must enter is a title, but a product with only a title looks unfinished.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Write the title.&lt;/strong&gt; Type "Handmade Cotton Tote Bag" in the Title field, and keep it short, specific and honest. Shopify builds the product web address from this title, so a clear title also gives you a clean URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Write the description.&lt;/strong&gt; Write two or three short paragraphs: what the bag is made of, what it holds, and how to wash it. Our example reads: "A sturdy handmade tote bag in thick cotton canvas. It holds a 15 inch laptop, a book and a water bottle, with room to spare. Machine washable, and the colour stays strong after washing." The &lt;a href="https://help.shopify.com/en/manual/products/add-update-products" rel="noopener noreferrer"&gt;official Shopify guide to adding and updating products&lt;/a&gt; lists every field on this page if you want to check what each one does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Add photos.&lt;/strong&gt; In the Media section, upload two or three photos: the bag on its own, the bag being carried, and a close up of the fabric. Use real photos of the real item in daylight. A product with no photo looks like an empty shelf.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Set the price.&lt;/strong&gt; In the Pricing section, type 14.99 in the Price field. You can also set a Compare-at price for sales, but leave it blank unless the bag is genuinely on sale. Here is a trap for beginners: if you do not enter a price at all, Shopify saves the product with a price of 0.00.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Add the colour variants.&lt;/strong&gt; Our bag comes in two colours, so it needs variants. In the Variants section, click Add options, choose Color, and type Natural and Forest Green as the values. Shopify creates one variant for each colour, each with its own price, photo and stock count. The &lt;a href="https://help.shopify.com/en/manual/products/variants" rel="noopener noreferrer"&gt;official Shopify guide to product variants&lt;/a&gt; explains options and values with a T-shirt example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Set the stock.&lt;/strong&gt; In the Inventory section, tick Track quantity, then enter how many bags you actually have: 20 in Natural and 15 in Forest Green, say. Shopify stops selling a variant when its count reaches zero.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Check the status and save.&lt;/strong&gt; At the top of the page, the Product status is set to Active by default, which means the product appears in your store as soon as you save. Draft hides it while you keep working. Leave it Active, check the Search engine listing preview, and click Save.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbto9qegtg0ge2r0agwal.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbto9qegtg0ge2r0agwal.png" alt="Screenshot of the Shopify Help Center page 'Adding and updating products' on help.shopify.com, showing the introduction and the Shopify Academy video" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Shopify Help Center page "Adding and updating products", the official guide for the steps above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before You Hit Save: A Quick Checklist
&lt;/h2&gt;

&lt;p&gt;Run through this list every time you add a product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Title:&lt;/strong&gt; short, specific, spelled correctly. Read it out loud. If it sounds like a real shelf label, it is good.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; at least two short paragraphs that answer what it is, what it is made of, and what it is for. No copied manufacturer text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Photos:&lt;/strong&gt; at least two real photos of the actual product, the right way up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Price:&lt;/strong&gt; typed in and double checked. Not 0.00, and not missing a digit. $14.99, not $149.90.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variants:&lt;/strong&gt; every colour and size you actually sell is listed, and each one has its own stock count.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stock:&lt;/strong&gt; counts match what is really in your stockroom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Status:&lt;/strong&gt; Active if you want shoppers to see it now, Draft if you are still working on it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search listing:&lt;/strong&gt; the preview title and description read well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Many Products at Once with a CSV File
&lt;/h2&gt;

&lt;p&gt;Adding products one by one is fine for your first five. By product number fifty, your fingers will beg for a shortcut, and Shopify has one: a CSV file. Each row is one product, and each column is one field. Here is a tiny example with our tote bag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Handle,Title,Price
handmade-cotton-tote,Handmade Cotton Tote Bag,14.99
handmade-cotton-tote,Handmade Cotton Tote Bag,14.99
handmade-cotton-tote,Handmade Cotton Tote Bag,14.99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Handle is the short label Shopify uses to group rows that belong to the same product, so all three rows share the handle handmade-cotton-tote. A real file would add columns for variant colour, stock count and image address. In the admin, go to Products, click Import, upload the file, and Shopify shows you a preview before it adds anything. Check the preview carefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes and How to Fix Them
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Your product shows a price of $0.00.&lt;/strong&gt; You saved it without entering a price. Open the product, type the real price, and save again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your product is nowhere in the store.&lt;/strong&gt; Check the Product status first. If it says Draft, shoppers cannot see it. Change it to Active and save. If it is Active and still missing, check that the Online Store sales channel is switched on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One colour is sold out on day one.&lt;/strong&gt; You probably set the stock on the product but not on the variant. Each variant has its own count, so open the variant and set its quantity separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your description is the same as ten other stores.&lt;/strong&gt; You copied the supplier text. Rewrite it in your own words with one detail only you would know, like what fits inside the bag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions Beginners Keep Asking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How many products do I need before I open my store?
&lt;/h3&gt;

&lt;p&gt;One good product is enough to open, but five to ten finished products make a store feel real.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I add a product without photos?
&lt;/h3&gt;

&lt;p&gt;Yes, Shopify lets you save a product with no photos at all. It is a bad idea though. Shoppers buy with their eyes first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I change the price later?
&lt;/h3&gt;

&lt;p&gt;Yes. Open the product, change the price, and click Save. The new price applies at once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need variants for a product with one version?
&lt;/h3&gt;

&lt;p&gt;No. If your bag comes in one colour and one size, skip the Variants section completely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I sell a product that is out of stock?
&lt;/h3&gt;

&lt;p&gt;By default, no. When Track quantity is on and the count hits zero, Shopify stops selling it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to Do Next
&lt;/h2&gt;

&lt;p&gt;Your first product is live, and the shelf is no longer empty. Now make it easy to find. Group your products into a collection, so shoppers can browse "Tote Bags" instead of hunting through everything. Then set up a simple discount, and place a test order yourself to see what your customer sees.&lt;/p&gt;

&lt;p&gt;After that, watch what happens. Our guide to &lt;a href="https://codingcush.com/shopify-analytics-explained" rel="noopener noreferrer"&gt;how to read your Shopify analytics&lt;/a&gt; shows which products get viewed and which ones get ignored. And when shoppers start leaving items in their carts, read our guide to &lt;a href="https://codingcush.com/shopify-abandoned-cart-recovery-guide" rel="noopener noreferrer"&gt;recover abandoned carts on Shopify&lt;/a&gt; to win some of those sales back. A finished product, a collection, and a test order is a real store.&lt;/p&gt;

</description>
      <category>shopify</category>
      <category>ecommerce</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript localStorage Explained with Simple Examples</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Mon, 30 Nov 2026 06:00:55 +0000</pubDate>
      <link>https://dev.to/kushkrg/javascript-localstorage-explained-with-simple-examples-2bjh</link>
      <guid>https://dev.to/kushkrg/javascript-localstorage-explained-with-simple-examples-2bjh</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/javascript-localstorage-explained" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript localStorage is a small storage box built into the browser that lets a website save text and read it back later, even after the tab is closed and the browser is restarted. It stores data as key and value pairs, holds about 5 MB per website, and never sends anything to the server. If you have ever picked dark mode on a website and found it still dark the next day, localStorage probably did that. Below: how it compares with its rivals, the four methods that do the work, and a theme toggle that remembers your choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  localStorage vs sessionStorage vs Cookies: The Comparison First
&lt;/h2&gt;

&lt;p&gt;Beginners mix these three up because they all "remember things". This table settles it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;localStorage&lt;/th&gt;
&lt;th&gt;sessionStorage&lt;/th&gt;
&lt;th&gt;Cookies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lifetime&lt;/td&gt;
&lt;td&gt;No expiry. Stays until deleted.&lt;/td&gt;
&lt;td&gt;Gone when the tab closes.&lt;/td&gt;
&lt;td&gt;You set the expiry, or it ends with the session.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Size&lt;/td&gt;
&lt;td&gt;About 5 MB per website.&lt;/td&gt;
&lt;td&gt;About 5 MB per website.&lt;/td&gt;
&lt;td&gt;About 4 KB per cookie.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sent to the server?&lt;/td&gt;
&lt;td&gt;No. It stays in the browser.&lt;/td&gt;
&lt;td&gt;No. It stays in the browser.&lt;/td&gt;
&lt;td&gt;Yes, with every request.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scope&lt;/td&gt;
&lt;td&gt;Every tab of the same website shares it.&lt;/td&gt;
&lt;td&gt;One tab only.&lt;/td&gt;
&lt;td&gt;Sent with requests to that domain.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Settings, themes, a saved name.&lt;/td&gt;
&lt;td&gt;Temporary data for one tab.&lt;/td&gt;
&lt;td&gt;Logins and server sessions.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two rows matter most. First, lifetime: localStorage has no expiry date while sessionStorage dies with the tab, so a theme choice belongs in localStorage and a half filled form in one tab belongs in sessionStorage. Second, the server row: cookies travel to the server with every request, so they are the right tool when the server needs the data. For the full story on the server side, read &lt;a href="https://codingcush.com/php-sessions-vs-cookies-difference" rel="noopener noreferrer"&gt;how PHP sessions and cookies differ&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What localStorage Actually Is
&lt;/h2&gt;

&lt;p&gt;localStorage is a property of the browser window that gives you a Storage object for the current website. In friendly terms, every website gets its own little notebook inside your browser, and JavaScript can write notes in it and read them back on later visits. The notebook belongs to one origin, one combination of protocol, domain and port, so a page on https and the same page on http get different notebooks. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage" rel="noopener noreferrer"&gt;MDN reference for Window.localStorage&lt;/a&gt; states it plainly: the stored data is saved across browser sessions, and unlike sessionStorage it has no expiration time.&lt;/p&gt;

&lt;p&gt;One more thing worth knowing: localStorage is synchronous, which means the browser stops and waits while it reads or writes. For the small strings beginners store, that pause is too tiny to notice. If the word synchronous sounds new, read our explanation of &lt;a href="https://codingcush.com/what-is-javascript-event-loop-explained" rel="noopener noreferrer"&gt;the JavaScript event loop&lt;/a&gt; to see how the browser handles one task at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Four Methods You Need
&lt;/h2&gt;

&lt;p&gt;Almost everything you will ever do with localStorage uses four methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;setItem&lt;/strong&gt; saves a value under a key. &lt;strong&gt;getItem&lt;/strong&gt; reads it back. That pair covers most real uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Lavkush"&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="n"&gt;savedName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;savedName&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;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lavkush
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other two methods clean up. &lt;strong&gt;removeItem&lt;/strong&gt; deletes one key, and &lt;strong&gt;clear&lt;/strong&gt; wipes the whole notebook for that website:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"username"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"theme"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"dark"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&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="nb"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"theme"&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="nb"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&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;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;null
null
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the surprise in that output. Reading a key that does not exist returns null, not an empty string and not an error. Expect null and handle it, usually with a fallback value, as the theme example later in this article shows.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl5cy7bejhp4lpq3zqyq2.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl5cy7bejhp4lpq3zqyq2.png" alt="Screenshot of the MDN page Window: localStorage property on developer.mozilla.org, showing the definition that stored data is saved across browser sessions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The MDN page for Window: localStorage property, the official reference for the storage methods used in this guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Your Saved Data Disappears
&lt;/h2&gt;

&lt;p&gt;Read this section when your code looks right but the data is gone on the next visit. Four causes cover almost every case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You tested from a file on your computer.&lt;/strong&gt; Opening an HTML file straight from your disk gives it a file address, and the rules for localStorage on file addresses are undefined. Serve your page from a local server instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You are in a private or incognito window.&lt;/strong&gt; localStorage works there, but the data is cleared when the last private tab closes. That is by design, so test in a normal window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The browser is blocking storage.&lt;/strong&gt; If the user blocks cookies, most browsers treat that as an instruction to block persistent storage too, and localStorage calls can throw a SecurityError. Wrap your first setItem call in a try catch block so the page keeps working.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You stored it under http and looked for it under https.&lt;/strong&gt; The notebook belongs to one protocol, domain and port. Switching between http and https, or between localhost and 127.0.0.1, means switching notebooks. Pick one address and stick to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Saving an Object? Turn It into a String First
&lt;/h2&gt;

&lt;p&gt;localStorage stores strings only. That rule sounds harmless until you save an object and get a nasty surprise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Lavkush"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"beginner"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"dark"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[object Object]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript quietly converted your object into the string "[object Object]", and your data is gone. The fix is a two step habit: JSON.stringify turns the object into a string before saving, and JSON.parse turns it back into an object when you read it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&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="n"&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;savedUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&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="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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="nb"&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="n"&gt;savedUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;savedUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;theme&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;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lavkush
dark
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have the object back, you can pull single values out of it with &lt;a href="https://codingcush.com/javascript-destructuring-explained" rel="noopener noreferrer"&gt;JavaScript destructuring&lt;/a&gt;, a tidy way to grab name, theme and level in one line. Remember: stringify on the way in, parse on the way out, every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Careful: Numbers Come Back as Strings
&lt;/h2&gt;

&lt;p&gt;The same string only rule bites with numbers. Save the number 3, read it back, and you get the string "3". Add 1 and JavaScript glues the characters together instead of doing maths:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"visits"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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="n"&gt;visits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"visits"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="k"&gt;typeof&lt;/span&gt; &lt;span class="n"&gt;visits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;visits&lt;/span&gt; &lt;span class="o"&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="nb"&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;visits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string
31
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That second line is the classic beginner bug: "3" plus 1 becomes "31". The fix is one word, Number(), wrapped around the value before you do maths with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Theme Toggle That Remembers Your Choice
&lt;/h2&gt;

&lt;p&gt;Now the running example: one button that switches a page between light and dark mode and remembers the choice:&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;button&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"themeButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Switch to dark mode&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;button&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;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"themeButton"&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;applyTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"dark"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&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="s2"&gt;"dark-mode"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Switch to light mode"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&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="s2"&gt;"dark-mode"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Switch to dark mode"&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="n"&gt;savedTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"theme"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;"light"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;applyTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedTheme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;button&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="s2"&gt;"click"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&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="n"&gt;newTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"theme"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"dark"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"light"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"dark"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"theme"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newTheme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;applyTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newTheme&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three ideas make this work. First, the page load line reads the saved theme and falls back to "light" when getItem returns null on the very first visit. Second, the click handler flips the value and saves it before updating the screen, so the stored choice and the visible page can never disagree. Third, applyTheme does the visible work in one place. Read a saved value, fall back to a default, save on change: that is the shape of most localStorage code.&lt;/p&gt;

&lt;h2&gt;
  
  
  When localStorage Is the Wrong Tool
&lt;/h2&gt;

&lt;p&gt;A good developer knows when not to use a tool. Do not store passwords, tokens or anything secret in localStorage, because any JavaScript running on your page can read it. Do not store data the server needs, because localStorage never leaves the browser; cookies and server sessions exist for that job. Do not store large data such as image files or long lists; about 5 MB fills up fast, and for bigger jobs the browser offers IndexedDB instead. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API" rel="noopener noreferrer"&gt;Web Storage API overview on MDN&lt;/a&gt; lists these same boundaries and points to the bigger storage tools when you outgrow key and value pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions Beginners Keep Asking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is localStorage safe for storing passwords?
&lt;/h3&gt;

&lt;p&gt;No. Any script on the page can read localStorage, so a password or login token stored there is exposed. Keep secrets on the server and use secure cookies for logins.&lt;/p&gt;

&lt;h3&gt;
  
  
  How much data can localStorage hold?
&lt;/h3&gt;

&lt;p&gt;About 5 MB per website in most browsers. Saving more throws an error, so keep what you store small.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does localStorage work in private or incognito mode?
&lt;/h3&gt;

&lt;p&gt;Yes, but the data is cleared when the last private tab closes, so never rely on it for anything important there.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can another website read my localStorage data?
&lt;/h3&gt;

&lt;p&gt;No. Storage is separated by origin, so only pages from the same origin can read it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does localStorage need an internet connection?
&lt;/h3&gt;

&lt;p&gt;No. The data lives in the browser on the device, so it works fully offline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Quiz: Did It Stick?
&lt;/h2&gt;

&lt;p&gt;Three fast questions. First, which method reads a value back? Answer: getItem, with the key as its argument. Second, what do you get when you read a key that was never saved? Answer: null, so always plan a fallback value. Third, why does saving an object directly print "[object Object]"? Answer: localStorage stores strings only, so stringify first and parse on the way back. Three out of three means you are ready to build the theme toggle yourself.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>WordPress Custom Post Types Explained Simply for Beginners</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Mon, 30 Nov 2026 06:00:04 +0000</pubDate>
      <link>https://dev.to/kushkrg/wordpress-custom-post-types-explained-simply-for-beginners-1hfg</link>
      <guid>https://dev.to/kushkrg/wordpress-custom-post-types-explained-simply-for-beginners-1hfg</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/wordpress-custom-post-types-explained-simply" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A custom post type in WordPress is a new kind of content with its own admin menu and its own pages on your site. Posts are for blog articles and pages are for fixed content like About and Contact, but a custom post type stores a different kind, such as recipes or team members, in its own neat box. This tutorial shows you what one is, when you need one, and how to register one with a few lines of PHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Understand What a Custom Post Type Is
&lt;/h2&gt;

&lt;p&gt;WordPress ships with five built in post types: post, page, attachment, revision, and menu. Each one is a container for a different kind of content: a post appears in your blog feed, a page does not, and an attachment is a media file. A custom post type is just a sixth container that you define yourself.&lt;/p&gt;

&lt;p&gt;Picture a food blog with two hundred recipes stored as normal posts, mixed in with news updates in the same category list. Give the blog a Recipes post type instead, and the recipes get their own admin menu and their own archive page at yoursite.com/recipes/. If WordPress itself is still new to you, read our guide to &lt;a href="https://codingcush.com/what-is-wordpress-explained-simply" rel="noopener noreferrer"&gt;what WordPress is, explained simply&lt;/a&gt; first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Decide When You Actually Need One
&lt;/h2&gt;

&lt;p&gt;Not every site needs one. Ask one question: does this content repeat with the same shape every time?&lt;/p&gt;

&lt;p&gt;You need one when the shape repeats. A recipe always has a title, ingredients, and steps. A portfolio project always has a title, a screenshot, and a link. Events, products, and testimonials fit the same pattern.&lt;/p&gt;

&lt;p&gt;You do not need one when a category or a tag would do the job. Ten travel stories are just posts in a Travel category. If the content will grow into a collection, give it its own post type. If it is a one off, do not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Register Your Post Type With Code
&lt;/h2&gt;

&lt;p&gt;You register a post type with one WordPress function, register_post_type(), hooked to the init action. We will register a Recipes post type as our example. The official &lt;a href="https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/" rel="noopener noreferrer"&gt;Registering Custom Post Types guide in the WordPress Plugin Handbook&lt;/a&gt; shows the same pattern.&lt;/p&gt;

&lt;p&gt;The official docs recommend putting custom post types in a plugin rather than a theme, so your content stays portable if you change your theme later. If you are not sure how the two differ, read our guide to &lt;a href="https://codingcush.com/wordpress-theme-vs-plugin-difference" rel="noopener noreferrer"&gt;the difference between a WordPress theme and a plugin&lt;/a&gt;. Paste this into a tiny custom plugin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function codingcush_register_recipe_post_type() {
    register_post_type( 'recipe', array(
        'labels'       =&amp;gt; array(
            'name'          =&amp;gt; __( 'Recipes', 'codingcush' ),
            'singular_name' =&amp;gt; __( 'Recipe', 'codingcush' ),
        ),
        'public'       =&amp;gt; true,
        'has_archive'  =&amp;gt; true,
        'show_in_rest' =&amp;gt; true,
        'menu_icon'    =&amp;gt; 'dashicons-food',
        'supports'     =&amp;gt; array( 'title', 'editor', 'thumbnail', 'excerpt' ),
        'rewrite'      =&amp;gt; array( 'slug' =&amp;gt; 'recipes' ),
    ) );
}
add_action( 'init', 'codingcush_register_recipe_post_type' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function name is ours. register_post_type() takes a short key, 'recipe', and a list of settings. The key must be 20 characters or fewer, lowercase letters, numbers, dashes, and underscores only, and it must not be a reserved name like post, page, or attachment. The labels array sets the words shown in the admin area: Recipes in menus and Recipe on the single item screen. The __() function marks those words as translatable.&lt;/p&gt;

&lt;p&gt;The next three settings control visibility. 'public' =&amp;gt; true makes the post type visible on the front of the site and in the admin area. 'has_archive' =&amp;gt; true gives it an archive page at yoursite.com/recipes/. 'show_in_rest' =&amp;gt; true includes it in the REST API, which is what makes the modern block editor available. Skip that last one and you will be stuck with the old classic editor.&lt;/p&gt;

&lt;p&gt;'menu_icon' =&amp;gt; 'dashicons-food' picks the food icon for the admin menu. WordPress ships a set of icons called Dashicons, so you can swap in dashicons-book for books. 'supports' lists the editing features each recipe gets: a title box, the main editor, a featured image, and a short excerpt box. 'rewrite' sets the web address slug. The last line, add_action( 'init', ... ), runs our function on the init hook.&lt;/p&gt;

&lt;p&gt;Save the file, make sure your plugin is active, and look for a new Recipes menu in your admin sidebar. Then go to Settings, then Permalinks, and click Save Changes once, so the new addresses work instead of showing a 404 page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Post vs Page vs Custom Post Type
&lt;/h2&gt;

&lt;p&gt;The three content kinds look alike in the editor, but they behave differently:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Post&lt;/th&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;Custom Post Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Blog articles and news&lt;/td&gt;
&lt;td&gt;Fixed content like About&lt;/td&gt;
&lt;td&gt;Repeating content like recipes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shows in the blog feed&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No, unless you ask for it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Has its own archive page&lt;/td&gt;
&lt;td&gt;Yes, the blog page&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes, if has_archive is true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Has its own admin menu&lt;/td&gt;
&lt;td&gt;Yes, Posts&lt;/td&gt;
&lt;td&gt;Yes, Pages&lt;/td&gt;
&lt;td&gt;Yes, named after your type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parent and child items&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Only if hierarchical is true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Example address&lt;/td&gt;
&lt;td&gt;/hello-world/&lt;/td&gt;
&lt;td&gt;/about/&lt;/td&gt;
&lt;td&gt;/recipes/chocolate-cake/&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Posts are time based and pages are fixed, while a custom post type is whatever collection your site needs.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo99l09m3umgonkl61hx2.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo99l09m3umgonkl61hx2.png" alt="Screenshot of the Registering Custom Post Types page in the WordPress Plugin Handbook on developer.wordpress.org, showing the five default post types and the recommendation to put custom post types in a plugin" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The official Registering Custom Post Types page in the WordPress Plugin Handbook, the starting point for this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Make It Show on Your Site
&lt;/h2&gt;

&lt;p&gt;Registering the post type is only half the job. Now check the menu, the archive page, and the single item page.&lt;/p&gt;

&lt;p&gt;First, the menu. Go to Appearance, then Menus, and add the recipe archive to your menu.&lt;/p&gt;

&lt;p&gt;Second, the archive page. Because we set has_archive to true, yoursite.com/recipes/ already lists every recipe. If it shows a 404 error, save your permalinks again.&lt;/p&gt;

&lt;p&gt;Third, the single recipe page. WordPress looks for single-recipe.php in your theme and falls back to single.php. For archives the same idea applies: archive-recipe.php, then archive.php.&lt;/p&gt;

&lt;p&gt;For a custom list of recipes, a small WP_Query loop does it. This example shows the six newest recipes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$recipes = new WP_Query( array(
    'post_type'      =&amp;gt; 'recipe',
    'posts_per_page' =&amp;gt; 6,
) );

if ( $recipes-&amp;gt;have_posts() ) {
    while ( $recipes-&amp;gt;have_posts() ) {
        $recipes-&amp;gt;the_post();
        the_title( '&amp;lt;h2&amp;gt;', '&amp;lt;/h2&amp;gt;' );
        the_excerpt();
    }
    wp_reset_postdata();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WP_Query asks WordPress for items of the recipe type, six at a time. have_posts() checks whether any exist, the_post() loads each one, the_title() prints its title, and the_excerpt() prints its summary. wp_reset_postdata() restores the main page query afterwards. Every argument is documented on the official &lt;a href="https://developer.wordpress.org/reference/functions/register_post_type/" rel="noopener noreferrer"&gt;register_post_type() reference page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: The Plugin Shortcut (No Code Needed)
&lt;/h2&gt;

&lt;p&gt;If PHP is not your thing yet, you do not have to write a single line. Plugins like Custom Post Type UI register post types through a settings form: type the name and labels, tick the boxes, and it generates the registration for you.&lt;/p&gt;

&lt;p&gt;The trade off is dependence: a form built post type works only while that plugin is active, while the code version is portable. Start with a plugin if you are in a hurry, then switch to the code version once the recipe example above makes sense. Either way, you will need to know &lt;a href="https://codingcush.com/how-to-install-a-wordpress-plugin" rel="noopener noreferrer"&gt;how to install a WordPress plugin&lt;/a&gt; first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes and How to Fix Them
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Recipes menu does not appear.&lt;/strong&gt; Check that the plugin holding your code is active and the code is hooked to init. One missing comma stops the whole file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single recipes and the archive page show a 404 error.&lt;/strong&gt; Go to Settings, then Permalinks, and press Save Changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The block editor is missing.&lt;/strong&gt; Your post type is registered without 'show_in_rest' =&amp;gt; true. Add that line and reload the editor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your content vanished after changing themes.&lt;/strong&gt; Your post type was registered inside the old theme, and it left with the theme. The posts are still in the database, so move the code into a small plugin and reactivate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions Beginners Keep Asking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do custom post types slow down WordPress?
&lt;/h3&gt;

&lt;p&gt;No. Registering a post type adds a tiny amount of setup work when WordPress loads. Site speed depends on hosting, theme, and images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I add categories to a custom post type?
&lt;/h3&gt;

&lt;p&gt;Yes. Add 'taxonomies' =&amp;gt; array( 'category', 'post_tag' ) to your settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I turn normal posts into a custom post type later?
&lt;/h3&gt;

&lt;p&gt;There is no built in convert button. If a collection will grow, give it its own post type from the start.&lt;/p&gt;

&lt;h3&gt;
  
  
  Will my recipes disappear if I change my theme?
&lt;/h3&gt;

&lt;p&gt;Only if it was registered in the theme. Put the registration in a plugin and your recipes will survive any theme change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Next Steps
&lt;/h2&gt;

&lt;p&gt;A custom post type sounds technical until you try it, and then it feels obvious: a named box for one kind of content, with its own menu, its own editor, and its own pages.&lt;/p&gt;

&lt;p&gt;Your homework is small. Register the Recipes post type from Step 3, add three real recipes, and put the archive in your menu. Then open a single recipe and notice the address: /recipes/ followed by the recipe name.&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>php</category>
    </item>
    <item>
      <title>What Is Cloud Computing? Explained Simply for Beginners</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Sun, 29 Nov 2026 06:24:04 +0000</pubDate>
      <link>https://dev.to/kushkrg/what-is-cloud-computing-explained-simply-for-beginners-2g22</link>
      <guid>https://dev.to/kushkrg/what-is-cloud-computing-explained-simply-for-beginners-2g22</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/what-is-cloud-computing-explained-simply" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It is Saturday morning, and Meera's small saree shop is having its first big online sale. She posts the link at 9 am. By 9:05, five hundred people are trying to open her website at the same time, and the page just spins. By 9:10 the site is down, and the customers are gone. The shop did nothing wrong. Its website lived on one small server in one room, and that server could only handle so many visitors at once. Cloud computing fixes exactly this problem. Cloud computing is the on-demand delivery of IT resources over the Internet with pay-as-you-go pricing. Instead of buying, owning, and maintaining your own servers, you rent computing power, storage, and databases from a provider, use only what you need, and pay only for what you use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why One Server of Your Own Breaks
&lt;/h2&gt;

&lt;p&gt;A server is just a computer that answers requests, one after another, with fixed memory and processing power, like a shop with only three chairs. Ten visitors are fine. Five hundred at once form a queue, the answers slow down, and sooner or later the machine gives up. That is what happened on sale day: a server sized for a quiet Tuesday met a Saturday crowd.&lt;/p&gt;

&lt;p&gt;Buying a bigger server sounds like the fix, but it has three problems. First, you pay for the big machine all year, though you only need it on a few busy days. Second, buying takes time, while the sale is already over. Third, one machine is still one machine: if its hard disk dies or the power goes out, your website goes out with it. This is the problem the cloud was built to solve. Instead of owning the chairs, you rent a hall that grows and shrinks with the crowd.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three Mistakes Beginners Make With the Cloud
&lt;/h2&gt;

&lt;p&gt;Before we go further, the three mistakes that cause most beginner cloud trouble. First, many people think moving to the cloud means their site can never go down. It does not. Microsoft says data can be mirrored at multiple redundant sites for backup and disaster recovery, but you have to set that up. A backup you never tested is just a hope, so test a restore once, before you need it for real.&lt;/p&gt;

&lt;p&gt;Second, many people think the cloud is cheap, so they leave everything running. It is cheap only when you use what you need, because you pay for what you use. A forgotten test server still bills you on Sunday. Turn off anything you are not using, and set a billing alert on the very first day.&lt;/p&gt;

&lt;p&gt;Third, many people think the cloud handles all security. It handles part of it. The provider secures its own buildings and machines, but you still secure your side: strong passwords and access only for people who need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the Cloud Actually Is
&lt;/h2&gt;

&lt;p&gt;Amazon Web Services puts it like this: cloud computing is the on-demand delivery of IT resources over the Internet with pay-as-you-go pricing, and instead of buying, owning, and maintaining physical data centers and servers, you can access technology services such as computing power, storage, and databases on an as-needed basis. The &lt;a href="https://aws.amazon.com/what-is-cloud-computing/" rel="noopener noreferrer"&gt;AWS cloud computing page&lt;/a&gt; explains this in full. On-demand means you ask and you get it in minutes, not weeks. &lt;a href="https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-cloud-computing" rel="noopener noreferrer"&gt;Microsoft's cloud computing guide&lt;/a&gt; agrees: most cloud services are provided self service and on demand, so even large amounts of computing resources can be provisioned in minutes. Pay-as-you-go means the bill follows your use. A quiet week and a busy Saturday cost what they use, not a giant machine all year. Rented, not owned, means the provider buys the buildings, the power, the cooling, and the machines. You already use it daily: webmail, photo backup, and streaming all run on someone else's computers. The cloud is not a place in the sky. It is other people's computers, in data centers, rented by the minute.&lt;/p&gt;

&lt;h2&gt;
  
  
  IaaS, PaaS, and SaaS: Three Ways to Rent
&lt;/h2&gt;

&lt;p&gt;Cloud services come at three levels, and your level decides how much work stays yours. Infrastructure as a Service, or IaaS, gives you the basic building blocks: virtual computers, storage, and networking. Amazon says IaaS gives you the highest level of flexibility and management control. You still look after the operating system and software, but the hardware is someone else's problem. Platform as a Service, or PaaS, goes one step further: it removes the need to manage the underlying infrastructure, so you can focus on your applications. You write code, upload it, and the platform runs it. Software as a Service, or SaaS, is a complete product run and managed by the provider. Webmail is the classic example. If your team runs apps in containers, &lt;a href="https://codingcush.com/what-is-kubernetes-explained-simply" rel="noopener noreferrer"&gt;Kubernetes, explained simply&lt;/a&gt;, shows how teams manage lots of them at once.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;What you rent&lt;/th&gt;
&lt;th&gt;Who manages the machine&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;IaaS&lt;/td&gt;
&lt;td&gt;Virtual computers, storage, networking&lt;/td&gt;
&lt;td&gt;Provider: hardware. You: the rest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PaaS&lt;/td&gt;
&lt;td&gt;A platform to build and run apps&lt;/td&gt;
&lt;td&gt;Provider: hardware and operating system&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SaaS&lt;/td&gt;
&lt;td&gt;A finished app you just use&lt;/td&gt;
&lt;td&gt;Provider: everything&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Clouds also come in three flavours: public, private, and hybrid. A public cloud is run by a third-party provider and shared by many companies, and it is the normal starting point for a small shop. A private cloud is owned by one organization, and a hybrid mixes the two.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1jtg85ipws6dk22z3gi.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1jtg85ipws6dk22z3gi.png" alt="Screenshot of Amazon Web Services' What is cloud computing page, showing the definition of cloud computing as the on-demand delivery of IT resources over the Internet with pay-as-you-go pricing" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Amazon Web Services' "What is cloud computing" page, with its definition of cloud computing.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Two-Minute Check That Your Site Is Alive
&lt;/h2&gt;

&lt;p&gt;Moving to the cloud does not mean you stop checking on your site. The simplest health check is one curl command: it asks your site for its front page and reports the answer and how long it took. Run it after any move or deploy, and again on sale day. Here it is, run against this very site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -s -o /dev/null -w "HTTP status: %{http_code}\nTime taken: %{time_total} seconds\n" https://codingcush.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP status: 200
Time taken: 1.294668 seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number 200 means the site answered fine. A number like 500 means the server is sick, and no connection at all means the site is down. Save this command in your notes. It costs nothing, and it is the first thing to run whenever someone says the site is not working.&lt;/p&gt;

&lt;h2&gt;
  
  
  How a Small Shop Would Actually Move to the Cloud
&lt;/h2&gt;

&lt;p&gt;So how would Meera's shop move? Not all at once, and not in one scary weekend. Move the easy parts first: the shop's photos and pages. Put them behind a content delivery network, so copies of the site sit close to customers, and read &lt;a href="https://codingcush.com/what-is-a-cdn-explained-simply" rel="noopener noreferrer"&gt;what a CDN does, explained simply&lt;/a&gt;, before you set one up. That alone helps on the next busy day.&lt;/p&gt;

&lt;p&gt;Next, move the app itself to a platform service, a PaaS. You upload the same code, the platform runs it, and you can raise the number of running copies for a sale, then lower it after. Then, if the shop grows, pack the app into containers, and learn &lt;a href="https://codingcush.com/what-is-docker-compose-explained" rel="noopener noreferrer"&gt;what Docker Compose does&lt;/a&gt; to run them together on your own machine first. Keep the two habits from earlier: tested backups, and a billing alert set on day one. Google Cloud says new customers get $300 in free credits, and AWS and Microsoft both publish free tier pages, so try it with small test projects first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions Beginners Actually Ask
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is cloud computing in simple words?
&lt;/h3&gt;

&lt;p&gt;Cloud computing is renting computers, storage, and software over the internet instead of buying and looking after your own machines. You use what you need and pay for what you use.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is cloud computing free?
&lt;/h3&gt;

&lt;p&gt;Not forever, but trying it costs little or nothing. Google Cloud says new customers get $300 in free credits, and AWS and Microsoft both publish free tier pages. Check the provider's own free tier page before you start, and set a billing alert on day one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need the cloud for a small website?
&lt;/h3&gt;

&lt;p&gt;Not always. A quiet blog or a small shop page can live happily on simple shared hosting. The cloud earns its keep when your traffic jumps around, when you want data copied to more than one place, or when you are tired of fixing servers yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is my data safe in the cloud?
&lt;/h3&gt;

&lt;p&gt;Safer than on one machine in one room, if you do your part. Microsoft notes that cloud providers offer a broad set of policies, technologies, and controls that strengthen your security posture. Your part is strong passwords, access only for people who need it, and tested backups.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Short Ending
&lt;/h2&gt;

&lt;p&gt;Meera's sale failed because one small server met five hundred visitors at once, and the fix was never a bigger box in the same room. The cloud rents you as much computer as the moment needs. Start with the free tier, test your backups, and set a billing alert. Your next sale day will still be busy. This time, the website will be ready.&lt;/p&gt;

</description>
      <category>cloudcomputing</category>
      <category>devops</category>
      <category>beginners</category>
      <category>aws</category>
    </item>
    <item>
      <title>What Is HTML? Explained Simply for Beginners</title>
      <dc:creator>Lavkush Kumar</dc:creator>
      <pubDate>Sun, 29 Nov 2026 06:14:28 +0000</pubDate>
      <link>https://dev.to/kushkrg/what-is-html-explained-simply-for-beginners-1nb7</link>
      <guid>https://dev.to/kushkrg/what-is-html-explained-simply-for-beginners-1nb7</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codingcush.com/what-is-html-explained-simply" rel="noopener noreferrer"&gt;CodingCush&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;HTML is the language that gives a web page its structure. It stands for HyperText Markup Language. Tags are small labels that tell the browser "this is a heading" or "this is a paragraph", and the browser turns those labels into the page you see. HTML does not decide colours or layouts, and it does not make buttons do things when clicked. It builds the skeleton. The rest is added on top.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, What a Tag Actually Is
&lt;/h2&gt;

&lt;p&gt;A tag is a short instruction inside angle brackets, like &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;. Most tags come in pairs: open &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, write text, close &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt;. The three parts together are called an element. Here is the smallest one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;Chai is ready.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; one plain line: "Chai is ready." Some tags carry attributes, extra information inside the opening tag, such as &lt;code&gt;lang="en"&lt;/code&gt;, which says the page is in English. The &lt;a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Your_first_website/Creating_the_content" rel="noopener noreferrer"&gt;MDN guide to creating the content of your first page&lt;/a&gt; explains the same idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Skeleton: Every Page Starts the Same Way
&lt;/h2&gt;

&lt;p&gt;Every web page starts with the same skeleton. We will build one page for a made up tea shop, Sharma Chai Stall, growing it tag by tag. The shop and prices are invented. Here it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
  &amp;lt;title&amp;gt;Sharma Chai Stall&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; a blank page whose tab reads "Sharma Chai Stall". &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt; tells the browser this is a modern HTML page. &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; wraps the whole page. The &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; holds unseen information, such as the tab title, while the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; holds everything visitors see. Save this skeleton for every page you build.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the Heading and the Welcome
&lt;/h2&gt;

&lt;p&gt;Now the first real content goes inside the body. Headings run from &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, the biggest, down to &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;, the smallest. A page has exactly one &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, the page name. Add these inside the body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Sharma Chai Stall&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Hot chai, fresh bun maska, and good company on Station Road since 2015.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; a large bold heading, "Sharma Chai Stall", with a smaller line under it. The browser makes the heading big and bold all by itself. Our guide to &lt;a href="https://codingcush.com/what-is-tailwind-css-explained-simply" rel="noopener noreferrer"&gt;what Tailwind CSS is, explained simply&lt;/a&gt; shows how small classes can style a page like this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the Menu as a List
&lt;/h2&gt;

&lt;p&gt;A stall without a menu is just a kettle. An ordered list, &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;, numbers its items. An unordered list, &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;, puts a bullet in front of each item, which suits a menu. Each item goes inside an &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; tag. Add this next:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Our Menu&amp;lt;/h2&amp;gt;
&amp;lt;ul&amp;gt;
  &amp;lt;li&amp;gt;Masala Chai&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;Adrak Chai&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;Cutting Chai&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;Bun Maska&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; a smaller heading, "Our Menu", over four bulleted lines. Swap &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; for &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; and the bullets become numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a Photo and a Link
&lt;/h2&gt;

&lt;p&gt;Next, a photo and a link. The image tag is the odd one out: no closing tag, no text inside it, everything from attributes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="chai.jpg" alt="A hot cup of masala chai at Sharma Chai Stall"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;src&lt;/code&gt; attribute says where the picture lives, and &lt;code&gt;alt&lt;/code&gt; says what it shows. If the picture fails to load, the browser shows the alt text instead, and screen readers read it aloud. Never skip it. Here &lt;code&gt;chai.jpg&lt;/code&gt; does not exist yet, so the browser shows a broken picture icon with the alt text beside it. Add a real photo named &lt;code&gt;chai.jpg&lt;/code&gt; to the same folder and it appears.&lt;/p&gt;

&lt;p&gt;The anchor tag, &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;, wraps text, and its &lt;code&gt;href&lt;/code&gt; says where the link goes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;Come and visit us, or &amp;lt;a href="https://codingcush.com"&amp;gt;learn to build pages like this one&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; a line of text with a blue underlined link in it. That is the "HyperText" in HTML: text that links to other pages.&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%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkb0s3rvp00vj9q4w36uy.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkb0s3rvp00vj9q4w36uy.png" alt="Screenshot of the MDN page HTML: Creating the content, showing the definition of HTML and the learning outcomes for elements, attributes, head and body" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The MDN page "HTML: Creating the content", which defines HTML and lists elements and attributes as learning outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the Price List as a Table
&lt;/h2&gt;

&lt;p&gt;A menu says what exists, a price list says what it costs, and that job belongs to a table. Tables are built from rows of cells. The header row uses &lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt; cells, shown in bold, and the other rows use &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; cells. Add this next:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Price List&amp;lt;/h2&amp;gt;
&amp;lt;table&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;th&amp;gt;Item&amp;lt;/th&amp;gt;
    &amp;lt;th&amp;gt;Price&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;Masala Chai&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;Rs. 10&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;Adrak Chai&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;Rs. 15&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;Cutting Chai&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;Rs. 7&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;Bun Maska&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;Rs. 20&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;p&amp;gt;Open every day, 6 in the morning to 10 at night.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; a neat two column table with a bold header row, four rows of prices, and a closing line about the opening hours. Never use a table to lay out a whole page. Tables are for data in rows and columns, like prices. Layout is a CSS job, and our guide to &lt;a href="https://codingcush.com/how-to-center-a-div-in-css" rel="noopener noreferrer"&gt;how to center a div in CSS&lt;/a&gt; shows how CSS takes over once HTML has done the structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Finished Page, All Together
&lt;/h2&gt;

&lt;p&gt;That is the whole stall. Here is the complete page. Save it as &lt;code&gt;chai-stall.html&lt;/code&gt; and open it in your browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
  &amp;lt;title&amp;gt;Sharma Chai Stall&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;Sharma Chai Stall&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;Hot chai, fresh bun maska, and good company on Station Road since 2015.&amp;lt;/p&amp;gt;
  &amp;lt;h2&amp;gt;Our Menu&amp;lt;/h2&amp;gt;
  &amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;Masala Chai&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;Adrak Chai&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;Cutting Chai&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;Bun Maska&amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;
  &amp;lt;img src="chai.jpg" alt="A hot cup of masala chai at Sharma Chai Stall"&amp;gt;
  &amp;lt;p&amp;gt;Come and visit us, or &amp;lt;a href="https://codingcush.com"&amp;gt;learn to build pages like this one&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;
  &amp;lt;h2&amp;gt;Price List&amp;lt;/h2&amp;gt;
  &amp;lt;table&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;th&amp;gt;Item&amp;lt;/th&amp;gt;
      &amp;lt;th&amp;gt;Price&amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Masala Chai&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;Rs. 10&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Adrak Chai&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;Rs. 15&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Cutting Chai&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;Rs. 7&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Bun Maska&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;Rs. 20&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
  &amp;lt;p&amp;gt;Open every day, 6 in the morning to 10 at night.&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected output:&lt;/strong&gt; the full stall page, in the order the tags appear in the file. That order is the whole secret of HTML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common HTML Tags at a Glance
&lt;/h2&gt;

&lt;p&gt;Here are the tags in one place. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML" rel="noopener noreferrer"&gt;MDN HTML reference&lt;/a&gt; lists every element with a full page of its own.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tag&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Used in our stall page&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;h1&amp;gt; to &amp;lt;h6&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Headings, biggest to smallest&lt;/td&gt;
&lt;td&gt;The stall name and section titles&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A paragraph&lt;/td&gt;
&lt;td&gt;The welcome and the closing line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A bulleted list&lt;/td&gt;
&lt;td&gt;The menu&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A link&lt;/td&gt;
&lt;td&gt;The "learn to build pages" link&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A picture&lt;/td&gt;
&lt;td&gt;The chai photo placeholder&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A table and its rows and cells&lt;/td&gt;
&lt;td&gt;The price list&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Common Mistakes Beginners Make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting a closing tag.&lt;/strong&gt; If a whole page turns bold or becomes one giant link, a closing tag is missing above it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nesting tags in the wrong order.&lt;/strong&gt; Tags must close in the reverse of the order they opened, like &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;text&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using two &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tags.&lt;/strong&gt; A page gets one main heading. Use &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;h3&amp;gt;&lt;/code&gt; for sections, in order. Size is a CSS job.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping alt text on images.&lt;/strong&gt; An &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; without &lt;code&gt;alt&lt;/code&gt; leaves screen reader users with nothing, and a blank hole when the picture fails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Writing a whole page inside the head.&lt;/strong&gt; Nothing in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; shows on screen. If your page opens blank but the tab title is right, your content is in the head by mistake.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is HTML a programming language?
&lt;/h3&gt;

&lt;p&gt;No. HTML is a markup language. It describes and structures content, but it cannot make decisions or react to a click. That work belongs to JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to learn HTML before CSS and JavaScript?
&lt;/h3&gt;

&lt;p&gt;Yes, in that order. CSS styles the HTML you write, and JavaScript changes it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I build a website with only HTML?
&lt;/h3&gt;

&lt;p&gt;Yes. Our chai stall page is proof. It will look plain, but it will work in every browser, and you can style it with CSS later.&lt;/p&gt;

&lt;h3&gt;
  
  
  What should I learn after HTML?
&lt;/h3&gt;

&lt;p&gt;Learn CSS next, then JavaScript. After that, our guide on &lt;a href="https://codingcush.com/what-is-django-explained-simply" rel="noopener noreferrer"&gt;what Django is, explained simply&lt;/a&gt; shows how a web framework turns pages like this one into a full working site.&lt;/p&gt;

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

&lt;p&gt;HTML is a small set of tags that turn plain words into a structured page. You built a whole chai stall page with about a dozen of them. Save the finished page, make it your own, and you will have built your first real web page. Then learn CSS, and watch it come alive. Learning HTML for a job? Read our guide on &lt;a href="https://codingcush.com/how-to-get-first-it-job-as-fresher" rel="noopener noreferrer"&gt;how to get your first IT job as a fresher&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>html</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
