Frontend & browser·Layout, CSS and the cascade
you set the width to 300 pixels and the element takes up 340, because of padding you forgot to count.
Box model
The four concentric areas of every element — content, padding, border, margin — and the rules for how a declared width maps onto them. Under the default `content-box`, `width` sizes only the content area and padding and border are added on top, which is the single most common source of 'why is this element wider than I said'. Margins are outside the box entirely and do not participate in its size or its background.