The Earth is attracted to the Sun because of gravity. The more mass an object has, the stronger its gravity.
All objects have a gravitational field which attracts other objects.
Your body, for instance, is gravitationally attracting all other objects around it. You don't notice this because you need a lot of mass to feel any noticeable pull. But, what is noticeable is the pull of the Earth keeping you stuck to the floor. Just like the Earth is pulling you down, the Sun is pulling the Earth towards it. But the Earth is also moving around the Sun at just the right speed to counteract this pull.